def reportPerformance(self, X, y): y_pred = self.reg.predict(X) print "Explained variance: {0:.5f}".format( metrics.explained_variance_score(y, y_pred)), "\n" print "Mean abs error: {0:.5f}".format( metrics.mean_absolute_error(y, y_pred)), "\n" print "Mean sqrt error: {0:.5f}".format( metrics.mean_squared_error(y, y_pred)), "\n" print "R2 score: {0:.5f}".format(metrics.r2_score(y, y_pred)), "\n"
def measure_performance(est, X, y): y_pred = est.predict(X) print "Explained variance: {0:.5f}".format( metrics.explained_variance_score(y, y_pred)), "\n" print "Mean abs error: {0:.5f}".format( metrics.mean_absolute_error(y, y_pred)), "\n" print "Mean sqrt error: {0:.5f}".format( metrics.mean_squared_error(y, y_pred)), "\n" print "R2 score: {0:.5f}".format(metrics.r2_score(y, y_pred)), "\n"
def score(self, X, y): """Returns the coefficient of determination R^2 of the prediction. The coefficient R^2 is defined as (1 - u/v), where u is the regression sum of squares ((y - y_pred) ** 2).sum() and v is the residual sum of squares ((y_true - y_true.mean()) ** 2).sum(). Best possible score is 1.0, lower values are worse. Parameters ---------- X : array-like, shape = [n_samples, n_features] Training set. y : array-like, shape = [n_samples] Returns ------- z : float """ return r2_score(y, self.predict(X))
prediction_.extend(prediction) verbose('----------\n') verbose("Evaluation") if opts.mode in ['age', 'gender']: from sklearn.metrics.metrics import precision_score, recall_score, confusion_matrix, classification_report, accuracy_score, f1_score # Calculando desempeƱo print('Accuracy :', accuracy_score(y_, prediction_)) print('Precision :', precision_score(y_, prediction_)) print('Recall :', recall_score(y_, prediction_)) print('F-score :', f1_score(y_, prediction_)) print('\nClasification report:\n', classification_report(y_, prediction_)) print('\nConfussion matrix :\n', confusion_matrix(y_, prediction_)) else: from sklearn.metrics.metrics import mean_absolute_error, mean_squared_error, r2_score print('Mean Abs Error :', mean_absolute_error(y_, prediction_)) print('Mean Sqr Error :', mean_squared_error(y_, prediction_)) print('R2 Error :', r2_score(y_, prediction_)) #plots: #import matplotlib.pyplot as plt #confusion_matrix_plot = confusion_matrix(y_test, prediction) #plt.title('matriz de confusion') #plt.colorbar() #plt.xlabel() #plt.xlabel('categoria de verdad') #plt.ylabel('categoria predecida') #plt.show()
def measure_performance(est, X, y ): y_pred=est.predict(X) print "Explained variance: {0:.5f}".format(metrics.explained_variance_score(y,y_pred)),"\n" print "Mean abs error: {0:.5f}".format(metrics.mean_absolute_error(y,y_pred)),"\n" print "Mean sqrt error: {0:.5f}".format(metrics.mean_squared_error(y,y_pred)),"\n" print "R2 score: {0:.5f}".format(metrics.r2_score(y,y_pred)),"\n"
def reportPerformance( self, X, y ): y_pred=self.reg.predict(X) print "Explained variance: {0:.5f}".format(metrics.explained_variance_score(y,y_pred)),"\n" print "Mean abs error: {0:.5f}".format(metrics.mean_absolute_error(y,y_pred)),"\n" print "Mean sqrt error: {0:.5f}".format(metrics.mean_squared_error(y,y_pred)),"\n" print "R2 score: {0:.5f}".format(metrics.r2_score(y,y_pred)),"\n"
print X_train[123, :] ''' norm1 = np.linalg.norm(y_train) if norm1 != 0: y_train, y_test = y_train/norm1, y_test/norm1 print norm1 ''' print y_train.shape model = SVR(C=1.0, gamma=1.0) model = LinearRegression() lasso = Lasso(alpha=0.1).fit(X_train, y_train) enet = ElasticNet(alpha=0.1, l1_ratio=0.7).fit(X_train, y_train) y_pred = lasso.predict(X_test) print "MSE", mean_squared_error(y_test, y_pred) m = np.mean(y_test) print "MSE (Mean)", mean_squared_error(y_test, m * np.ones(len(y_test))) print "r^2 on test data", r2_score(y_test, y_pred) plt.plot(enet.coef_, label='Elastic net coefficients') plt.plot(lasso.coef_, label='Lasso coefficients') plt.legend(loc='best') plt.title("Lasso R^2: %f, Elastic Net R^2: %f" % (r2_score( y_test, lasso.predict(X_test)), r2_score(y_test, enet.predict(X_test)))) plt.show()
verbose('----------\n') verbose("Evaluation") if opts.mode in ['age','gender']: from sklearn.metrics.metrics import precision_score, recall_score, confusion_matrix, classification_report, accuracy_score, f1_score # Calculando desempeƱo print( 'Accuracy :', accuracy_score(y_, prediction_)) print( 'Precision :', precision_score(y_, prediction_)) print( 'Recall :', recall_score(y_, prediction_)) print( 'F-score :', f1_score(y_, prediction_)) print( '\nClasification report:\n', classification_report(y_, prediction_)) print( '\nConfussion matrix :\n',confusion_matrix(y_, prediction_)) else: from sklearn.metrics.metrics import mean_absolute_error, mean_squared_error,r2_score print( 'Mean Abs Error :', mean_absolute_error(y_, prediction_)) print( 'Mean Sqr Error :', mean_squared_error(y_, prediction_)) print( 'R2 Error :', r2_score(y_, prediction_)) #plots: #import matplotlib.pyplot as plt #confusion_matrix_plot = confusion_matrix(y_test, prediction) #plt.title('matriz de confusion') #plt.colorbar() #plt.xlabel() #plt.xlabel('categoria de verdad') #plt.ylabel('categoria predecida') #plt.show()
''' norm1 = np.linalg.norm(y_train) if norm1 != 0: y_train, y_test = y_train/norm1, y_test/norm1 print norm1 ''' print y_train.shape model = SVR(C=1.0, gamma=1.0) model = LinearRegression() lasso = Lasso(alpha=0.1).fit(X_train, y_train) enet = ElasticNet(alpha=0.1, l1_ratio=0.7).fit(X_train, y_train) y_pred = lasso.predict(X_test) print "MSE", mean_squared_error(y_test, y_pred) m = np.mean(y_test) print "MSE (Mean)",mean_squared_error(y_test, m*np.ones(len(y_test))) print "r^2 on test data", r2_score(y_test, y_pred) plt.plot(enet.coef_, label='Elastic net coefficients') plt.plot(lasso.coef_, label='Lasso coefficients') plt.legend(loc='best') plt.title("Lasso R^2: %f, Elastic Net R^2: %f" % (r2_score(y_test, lasso.predict(X_test)), r2_score(y_test, enet.predict(X_test)))) plt.show()