def main(): @run_time def batch(): print("Tesing the performance of LinearRegression(batch)...") # Train model reg = LinearRegression() reg.fit(X=X_train, y=y_train, lr=0.1, epochs=1000) # Model evaluation get_r2(reg, X_test, y_test) print(reg) @run_time def stochastic(): print("Tesing the performance of LinearRegression(stochastic)...") # Train model reg = LinearRegression() reg.fit(X=X_train, y=y_train, lr=0.05, epochs=50, method="stochastic", sample_rate=0.6) # Model evaluation get_r2(reg, X_test, y_test) print(reg) # Load data X, y = load_boston_house_prices() X = min_max_scale(X) # Split data randomly, train set rate 70% X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=20) batch() stochastic()
def main(): """Tesing the performance of LinearRegression. """ @run_time def batch(): print("Tesing the performance of LinearRegression(batch)...") # Train model reg = LinearRegression() reg.fit(data=data_train, label=label_train, learning_rate=0.1, epochs=1000) # Model evaluation get_r2(reg, data_test, label_test) print(reg) @run_time def stochastic(): print("Tesing the performance of LinearRegression(stochastic)...") # Train model reg = LinearRegression() reg.fit(data=data_train, label=label_train, learning_rate=0.05, epochs=50, method="stochastic", sample_rate=0.6) # Model evaluation get_r2(reg, data_test, label_test) print(reg) # Load data data, label = load_boston_house_prices() data = min_max_scale(data) # Split data randomly, train set rate 70% data_train, data_test, label_train, label_test = train_test_split( data, label, random_state=20) batch() stochastic()
def main(): print("Tesing the performance of KNN regressor...") # Load data X, y = load_boston_house_prices() X = min_max_scale(X) # Split data randomly, train set rate 70% X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=10) # Train model reg = KNeighborsRegressor() reg.fit(X=X_train, y=y_train, k_neighbors=3) # Model evaluation get_r2(reg, X_test, y_test)
def main(): print("Tesing the performance of RegressionTree...") # Load data X, y = load_boston_house_prices() # Split data randomly, train set rate 70% X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=10) # Train model reg = RegressionTree() reg.fit(X=X_train, y=y_train, max_depth=5) # Show rules reg.rules # Model evaluation get_r2(reg, X_test, y_test)
def main(): print("Tesing the performance of Ridge Regressor(stochastic)...") # Load data X, y = load_boston_house_prices() X = min_max_scale(X) # Split data randomly, train set rate 70% X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=10) # Train model reg = Ridge() reg.fit(X=X_train, y=y_train, lr=0.001, epochs=1000, method="stochastic", sample_rate=0.5, alpha=1e-7) # Model evaluation get_r2(reg, X_test, y_test)
def main(): print("Tesing the performance of GBDT regressor...") # Load data X, y = load_boston_house_prices() # Split data randomly, train set rate 70% X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=10) # Train model reg = GradientBoostingRegressor() reg.fit(X=X_train, y=y_train, n_estimators=4, lr=0.5, max_depth=3, min_samples_split=2) # Model evaluation get_r2(reg, X_test, y_test)
def main(): """Tesing the performance of RegressionTree """ print("Tesing the performance of RegressionTree...") # Load data data, label = load_boston_house_prices() # Split data randomly, train set rate 70% data_train, data_test, label_train, label_test = train_test_split( data, label, random_state=200) # Train model reg = RegressionTree() reg.fit(data=data_train, label=label_train, max_depth=5) # Show rules print(reg) # Model evaluation get_r2(reg, data_test, label_test)
def main(): """Tesing the performance of MLP. """ print("Tesing the performance of MLP....") # Load data data, label = load_boston_house_prices() data = min_max_scale(data) # Split data randomly, train set rate 70% data_train, data_test, label_train, label_test = train_test_split( data, label, random_state=20) # Train model reg = MLP() reg.fit(data=data_train, label=label_train, n_hidden=8, epochs=500, batch_size=8, learning_rate=0.0008) # Model evaluation get_r2(reg, data_test, label_test) print(reg)