python - how to properly use sklearn to predict the error of a fit -
i'm using sklearn fit linear regression model data. in particular, response variable stored in array y , features in matrix x.
i train linear regression model following piece of code
sklearn.linear_model import linearregression model = linearregression() model.fit(x,y) and seems fine.
then let's have new data x_new , want predict response variable them. can done doing
predictions = model.predict(x_new) my question is, error associated prediction? understanding should compute mean squared error of model:
sklearn.metrics import mean_squared_error model_mse = mean_squared_error(model.predict(x),y) and real predictions new data should random number computed gaussian distribution mean predictions , sigma^2 = model_mse. agree , know if there's faster way in sklearn?
you want validate model on training data set. suggest exploring cross-validation submodule sklearn.cross_validation.
the basic usage is:
from sklearn.cross_validation import train_test_split x_train, x_test, y_train, y_test = train_test_split(x, y)
Comments
Post a Comment