Found input variables with inconsistent number of samples

Viewed 39

I get the Used the following error when trying to do the score or mean squared error of a single sample :"Found input variables with inconsistent number of samples" for a decision tree regressor model from sklearn to find the chance of having a heart attack based on 13 other parameters. The model seems to work but the metrics tests always give me this kind of error regardless of how I transform the data. Its because the sample test is 1 row whilst the training data is 303 rows but I don't know how to fit them.

import pandas as pd

from sklearn import tree

from sklearn.metrics import mean_squared_error


heart = pd.read_csv('heart.csv')
test = pd.read_csv('Heart_test.csv')


X = heart.iloc[:,0:13]
Y = heart.iloc[:,13:14]

test = test.iloc[:,0:13]

#print(X.head(), '\n', test.head(),'\n')

model = tree.DecisionTreeRegressor()
model = model.fit(X,Y)

y_prediction = model.predict(test)

print(mean_squared_error(Y,y_prediction)
0 Answers
Related