def housing(): train, train_target, test, test_target = load_boston_house() normalize_columns = [0, 1, 2, 6, 7, 9, 10, 11, 12] normalize(train, normalize_columns) normalize(test, normalize_columns) train = append_new_column(train, 1.0, 0) test = append_new_column(test, 1.0, 0) lr = LinearRegression() lr.fit(train, train_target) print '=============Train Data Result============' predict = lr.predict(train) print "mse: ", mse(predict, train_target), " rmse: ", rmse(predict, train_target), " mae: ", mae(predict, train_target) print '=============Test Data Result============' predict = lr.predict(test) print "mse: ", mse(predict, test_target), " rmse: ", rmse(predict, test_target), " mae: ", mae(predict, test_target)
def regression_tree(): print "=========Start Train==============" train, train_target, test, test_target = load_boston_house() print len(train), len(test) classifier = tree.RegressionTree() classifier = classifier.fit(train, train_target, 2, -1) print "=========Finish Train==============" print "=========Tree==============" print_tree(classifier.root) print '=============Train Data Result============' predict = classifier.predict(train) print "mse: ", mse(predict, train_target), " rmse: ", rmse(predict, train_target), " mae: ", mae(predict, train_target) print '=============Test Data Result============' predict = classifier.predict(test) print "mse: ", mse(predict, test_target), " rmse: ", rmse(predict, test_target), " mae: ", mae(predict, test_target)
def housing(): train, train_target, test, test_target = load_boston_house() scaler = normalize(train) scaler.scale_test(test) train = append_new_column(train, 1.0, 0) test = append_new_column(test, 1.0, 0) lr = StochasticGradientDescendingRegression() # lr = GradientDescendingRegression() lr.fit(train, train_target, 0.0001, 500) print '---------------Stochastic Gradient----------' print '=============Train Data Result============' predict = lr.predict(train) print "mse: ", mse(predict, train_target), " rmse: ", rmse(predict, train_target), " mae: ", mae(predict, train_target) print '=============Test Data Result============' predict = lr.predict(test) print "mse: ", mse(predict, test_target), " rmse: ", rmse(predict, test_target), " mae: ", mae(predict, test_target) print '------------- Normal Equation--------------' lr = LinearRegression() lr.fit(train, train_target) print '=============Train Data Result============' predict = lr.predict(train) print "mse: ", mse(predict, train_target), " rmse: ", rmse(predict, train_target), " mae: ", mae(predict, train_target) print '=============Test Data Result============' predict = lr.predict(test) print "mse: ", mse(predict, test_target), " rmse: ", rmse(predict, test_target), " mae: ", mae(predict, test_target) print '---------------Regression Tree-----------' lr = RegressionTree() lr.fit(train, train_target, 2, 0) print '=============Train Data Result============' predict = lr.predict(train) print "mse: ", mse(predict, train_target), " rmse: ", rmse(predict, train_target), " mae: ", mae(predict, train_target) print '=============Test Data Result============' predict = lr.predict(test) print "mse: ", mse(predict, test_target), " rmse: ", rmse(predict, test_target), " mae: ", mae(predict, test_target)
def housing(): train, train_target, test, test_target = load_boston_house() normalize_columns = [0, 1, 2, 6, 7, 9, 10, 11, 12] normalize(train, normalize_columns) normalize(test, normalize_columns) train = append_new_column(train, 1.0, 0) test = append_new_column(test, 1.0, 0) lr = LinearRegression() lr.fit(train, train_target) print '=============Train Data Result============' predict = lr.predict(train) print "mse: ", mse(predict, train_target), " rmse: ", rmse( predict, train_target), " mae: ", mae(predict, train_target) print '=============Test Data Result============' predict = lr.predict(test) print "mse: ", mse(predict, test_target), " rmse: ", rmse( predict, test_target), " mae: ", mae(predict, test_target)
def regression_tree(): print "=========Start Train==============" train, train_target, test, test_target = load_boston_house() print len(train), len(test) classifier = tree.RegressionTree() classifier = classifier.fit(train, train_target, 2, -1) print "=========Finish Train==============" print "=========Tree==============" print_tree(classifier.root) print '=============Train Data Result============' predict = classifier.predict(train) print "mse: ", mse(predict, train_target), " rmse: ", rmse( predict, train_target), " mae: ", mae(predict, train_target) print '=============Test Data Result============' predict = classifier.predict(test) print "mse: ", mse(predict, test_target), " rmse: ", rmse( predict, test_target), " mae: ", mae(predict, test_target)