def main(): """Tesing the performance of LogisticRegression. """ @run_time def batch(): print("Tesing the performance of LogisticRegression(batch)...") # Train model clf = LogisticRegression() clf.fit(data=data_train, label=label_train, learning_rate=0.1, epochs=1000) # Model evaluation model_evaluation(clf, data_test, label_test) print(clf) @run_time def stochastic(): print("Tesing the performance of LogisticRegression(stochastic)...") # Train model clf = LogisticRegression() clf.fit(data=data_train, label=label_train, learning_rate=0.01, epochs=100, method="stochastic", sample_rate=0.8) # Model evaluation model_evaluation(clf, data_test, label_test) print(clf) # Load data data, label = load_breast_cancer() 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=10) batch() print() stochastic()
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(): print("Tesing the performance of Kmeans...") # Load data X, y = load_breast_cancer() X = min_max_scale(X) # Train model est = KMeans() k = 2 est.fit(X, k) print() # Model performance prob_pos = sum(y) / len(y) print("Positive probability of X is:%.1f%%.\n" % (prob_pos * 100)) y_hat = est.predict(X) cluster_pos_tot_cnt = {i: [0, 0] for i in range(k)} for yi_hat, yi in zip(y_hat, y): cluster_pos_tot_cnt[yi_hat][0] += yi cluster_pos_tot_cnt[yi_hat][1] += 1 cluster_prob_pos = {k: v[0] / v[1] for k, v in cluster_pos_tot_cnt.items()} for i in range(k): tot_cnt = cluster_pos_tot_cnt[i][1] prob_pos = cluster_prob_pos[i] print("Count of elements in cluster %d is:%d." % (i, tot_cnt)) print("Positive probability of cluster %d is:%.1f%%.\n" % (i, prob_pos * 100))
def main(): @run_time def batch(): print("Tesing the performance of LogisticRegression(batch)...") # Train model clf = LogisticRegression() clf.fit(X=X_train, y=y_train, lr=0.1, epochs=1000) # Model evaluation model_evaluation(clf, X_test, y_test) print(clf) @run_time def stochastic(): print("Tesing the performance of LogisticRegression(stochastic)...") # Train model clf = LogisticRegression() clf.fit(X=X_train, y=y_train, lr=0.01, epochs=100, method="stochastic", sample_rate=0.8) # Model evaluation model_evaluation(clf, X_test, y_test) print(clf) # Load data X, y = load_breast_cancer() 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) batch() print() 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 KNN classifier...") # Load data X, y = load_breast_cancer() 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) # Train model clf = KNeighborsClassifier() clf.fit(X_train, y_train, k_neighbors=21) # Model evaluation model_evaluation(clf, 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(): """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)