ValueError - "Found input variables with inconsistent numbers of samples: [100, 120]"

Joined
Jun 29, 2022
Messages
28
Reaction score
0
Hello,
I'm presently working on a supervised learning project using scikit-learn, similar to the example given here, and I've run into an issue that has me stumped. When I try to fit my data into a machine-learning model, I get the following error:
Code:
ValueError: Found input variables with inconsistent numbers of samples: [100, 120]
My characteristics and target labels were both loaded from different CSV files with the same amount of rows. However, I'm not clear why this inconsistency issue is occurring. Could someone please assist me in identifying the problem?

Here's a shortened version of my code:
Code:
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression

# Load the data from CSV files
X = pd.read_csv('features.csv')
y = pd.read_csv('labels.csv')

# Split the data into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Initialize and fit the logistic regression model
model = LogisticRegression()
model.fit(X_train, y_train)
I'd appreciate any help in fixing this inconsistency error. Thank you for your assistance!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,792
Messages
2,569,639
Members
45,353
Latest member
RogerDoger

Latest Threads

Top