Exemple #1
0
def linear_model(x_train, x_test, y_train, y_test):
    G = linear_regression(x_train, y_train)
    y_pred, rmse, mae, r2 = regression_predictor(G, x_test, y_test)
    val = cross_validation_regressor(model, x_train, y_train)
    stats = pd.DataFrame([(val, mae, rmse, r2)],
                         columns=['cross_val', 'rmse', 'mae', 'r2'])
    return G, y_pred, stats
def linear_model(x_train, x_test, y_train, y_test):
    model = linear_regression(x_train, y_train)
    val = cross_validation_regressor(model, x_train, y_train)
    y_pred, mse, mae, r2 = regression_predictor(model, x_test, y_test)
    rmse = (mse)
    d = {'0': val, '1': mae, '2': rmse, '3': r2}
    stats = pd.DataFrame(d, index=d.keys())
    stats.reset_index(drop=True, inplace=True)
    return model, y_pred, stats
Exemple #3
0
def linear_model(x_train, x_test, y_train, y_test):
    model = linear_regression(x_train, y_train)
    val = cross_validation_regressor(model, x_train, y_train)
    y_pred, mse, mae, r2 = regression_predictor(model, x_test, y_test)
    stats = pd.DataFrame(np.array([val, mae, mse, r2]).reshape(1, 4),
                         columns=['v', 'm', 's', 'r'],
                         index=[0])

    return model, y_pred, stats
def linear_model(x_train, x_test, y_train, y_test):
    model = linear_regression(x_train, y_train)
    val = cross_validation_regressor(model, x_train, y_train)
    y_pred, mse, mae, r2 = regression_predictor(model, x_test, y_test)
    stats = pd.DataFrame()
    stats['CV_score'] = val, val
    stats['MAE'] = mae
    stats['MSE'] = mse
    stats['r2'] = r2
    #stats.set_index('Name',inplace=True)
    return model, y_pred, stats
def linear_model(x_train, x_test, y_train, y_test):
    model = linear_regression(x_train, y_train)
    val = cross_validation_regressor(model, x_train, y_train)
    y_pred, mse, mae, r2 = regression_predictor(model, x_test, y_test)
    d = {
        'cross_validation': [val],
        'rmse': [mse],
        'mae': [mae],
        'rsquared': [r2]
    }
    stats = pd.DataFrame(data=d)
    return model, y_pred, stats
def linear_model(x_train, x_test, y_train, y_test):
    G = linear_regression(x_train, y_train)

    c_val = cross_validation_regressor(G, x_train, y_train)

    y_pred, mse, mae, r2 = regression_predictor(G, x_test, y_test)

    my_dict = {'c_val': c_val, 'mse': mse, 'mae': mae, 'r2': r2}

    stats = pd.DataFrame(my_dict, index=[0])

    return G, y_pred, stats
from sklearn.metrics import mean_squared_error, mean_absolute_error, r2_score

from greyatomlib.multivariate_regression_project.q01_load_data.build import load_data
from greyatomlib.multivariate_regression_project.q02_data_split.build import split_dataset

from greyatomlib.multivariate_regression_project.q03_data_encoding.build import label_encode
from greyatomlib.multivariate_regression_project.q05_linear_regression_model.build import linear_regression
from greyatomlib.multivariate_regression_project.q06_cross_validation.build import cross_validation_regressor

df = load_data('data/student-mat.csv')

x_train, x_test, y_train, y_test = split_dataset(df)

x_train, x_test = label_encode(x_train, x_test)

model = linear_regression(x_train, y_train)

val = cross_validation_regressor(model, x_train, y_train)
y_pred, mse, mae, r2 = regression_predictor(model, x_test, y_test)


class Test_regression_predictor(TestCase):
    def test_args(self):  # Input parameters tests
        args = getfullargspec(regression_predictor)
        self.assertEqual(len(args[0]), 3,
                         "Expected arguments %d, Given %d" % (2, len(args[0])))

    def test_y_pred_type(self):
        self.assertIsInstance(
            y_pred, np.ndarray,
            "Expected data type for 'return value' is float you are returning\
Exemple #8
0
def linear_model(x_train, x_test, y_train, y_test):
    G = linear_regression(x_train, y_train)
    stats = pd.DataFrame([(val,mae,mse,r2)], columns = ['cross_val','rmse','mae','r2'])
    
    return G, y_pred, stats
import matplotlib.pyplot as plt
import pylab
import scipy.stats as stats
from greyatomlib.multivariate_regression_project.q01_load_data.build import load_data
from greyatomlib.multivariate_regression_project.q02_data_split.build import split_dataset
from greyatomlib.multivariate_regression_project.q05_linear_regression_model.build import linear_regression
from greyatomlib.multivariate_regression_project.q07_regression_pred.build import regression_predictor
#from greyatomlib.linear_regression.q05_residuals.build import residuals
#from greyatomlib.multivariate_regression_project.q06_cross_validation import cross_validation_regressor

from sklearn.linear_model import LinearRegression
from greyatomlib.multivariate_regression_project.q03_data_encoding.build import label_encode

df = load_data('data/student-mat.csv')

x_train, x_test, y_train, y_test = split_dataset(df)

x_train, x_test = label_encode(x_train, x_test)
lin_reg = linear_regression(x_train, y_train)
y_pred, _, __, ___ = regression_predictor(lin_reg, x_test, y_test)


def plot_residuals(y_test, y_pred, name):
    error_residuals = y_test - y_pred
    stats.probplot(error_residuals, dist="norm", plot=pylab)
    return pylab.show()


#plot_residuals(y_test,y_pred,'name')