# Accuracy of machine learning models

I started learning ML and I have some problems with evaluating / finding the accuracy of regression and classification models. Till now I used .score() in both cases but people told me that Its not the accuracy. Then I tried to use this:

from sklearn.model_selection import train_test_split

from sklearn.metrics import accuracy_score
from sklearn.metrics import mean_squared_error

var_train, var_test, res_train, res_test = train_test_split(variables, results, test_size = 0.2, random_state = 4)

regression = linear_model.LinearRegression()
regression.fit(var_train, res_train)

input_values = [14, 2]

prediction = regression.predict([input_values])
accuracy_regression = mean_squared_error(var_test, prediction)


But I always get this error:

ValueError: Found input variables with inconsistent numbers of samples: [2, 1]


I have looked all over the udemy and youtube, and a lot of people are calculating accuracy like .score(). Then I looked all over scikit-learn website and stackoverflow and I saw the other solution with metrics but I keep getting the same error. What am I doing wrong?

https://stackoverflow.com/questions/56622349/accuracy-of-multivariate-classification-and-regression-models-with-scikit-learn

• What is the line that returns error? – Leevo Jun 17 '19 at 9:29
• The last line : accuracy_regression = mean_squared_error(var_test, prediction) Im trying to find a way to see accuracy / evaluation / score of my regression model. For example , your model is 89.53% accurate. Is that possible to do with regression models? – taga Jun 17 '19 at 9:36
• Can you check the shape/length of your objects var_test and prediction ? And if they contain any missing values? – Leevo Jun 17 '19 at 9:40

The fact that you are getting an error at mean_squared_error() is suggesting me that your input objects (input_values and var_test) must have either: different shapes, and/or contain missing values. In particular, you are only feeding two observations as input_values: [14, 2]. Is var_test a vector of length 2 ?
• var_test is (2,2). You can check the whole code here: stackoverflow.com/questions/56622349/… I managed to make it work, i didnt use prediction = regression.predict([input_values]), I have used prediction = regression.predict(var_test) but i get prediction value [697.5 426. ] and mean_squared_error 2086.625. – taga Jun 17 '19 at 9:55