def main(): data = load_iris_dataset(dir_path + r"/../data/iris.csv") X = data['X'] y = data['target'] # Change class labels from strings to numbers # df = df.replace(to_replace="setosa", value="-1") # df = df.replace(to_replace="virginica", value="1") # df = df.replace(to_replace="versicolor", value="2") # Only select data for two classes #X = df.loc[df['species'] != "2"].drop("species", axis=1).as_matrix() #y = df.loc[df['species'] != "2"]["species"].as_matrix() X = X[y != 2] y = y[y != 2] y[y == 0] = -1 X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33) # Adaboost classification clf = Adaboost(n_clf=8) clf.fit(X_train, y_train) y_pred = clf.predict(X_test) print "Accuracy:", accuracy_score(y_test, y_pred) # Reduce dimensions to 2d using pca and plot the results pca = PCA() pca.plot_in_2d(X_test, y_pred)
def main(): # Load the dataset data=load_iris_dataset(dir_path + r"/../data/iris.csv") X=data['X'] y=data['target'] # Project the data onto the 2 primary principal components and plot the # data pca = PCA() pca.plot_in_2d(X, y)
def main(): # Load the dataset data=load_iris_dataset(dir_path + r"/../data/iris.csv") X=data['X'] y=data['target'] X = normalize(X) # Project the data onto the 2 primary components multi_class_lda = MultiClassLDA() multi_class_lda.plot_in_2d(X, y)
def main(): # Load the dataset data = load_iris_dataset(dir_path + r"/../data/iris.csv") X = data['X'] y = data['target'] # Cluster the data using K-Medoids clf = PAM(k=3) y_pred = clf.predict(X) # Project the data onto the 2 primary principal components pca = PCA() pca.plot_in_2d(X, y_pred) pca.plot_in_2d(X, y)
def main(): data = load_iris_dataset(dir_path + r"/../data/iris.csv") X = data['X'] y = data['target'] X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.4) clf = RandomForest(n_estimators=50, debug=True) clf.fit(X_train, y_train) y_pred = clf.predict(X_test) print "Accuracy:", accuracy_score(y_test, y_pred) pca = PCA() pca.plot_in_2d(X_test, y_pred)
def main(): data=load_iris_dataset(dir_path + r"/../data/iris.csv") X=data['X'] y=data['target'] X = normalize(X) X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33) clf = KNN(k=3) y_pred = clf.predict(X_test, X_train, y_train) print "Accuracy score:", accuracy_score(y_test, y_pred) # Reduce dimensions to 2d using pca and plot the results pca = PCA() pca.plot_in_2d(X_test, y_pred)
def main(): data = load_iris_dataset(dir_path + r"/../data/iris.csv") X = data['X'] y = data['target'] X = normalize(X) X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33) # Perceptron clf = Perceptron() clf.fit(X_train, y_train, plot_errors=True) y_pred = clf.predict(X_test) print "Accuracy:", accuracy_score(y_test, y_pred) # Reduce dimension to two using PCA and plot the results pca = PCA() pca.plot_in_2d(X_test, y_pred)
def main(): data = load_iris_dataset(dir_path + r"/../data/iris.csv") X = data['X'] y = data['target'] X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.4) clf = DecisionTree() clf.fit(X_train, y_train) # clf.print_tree() y_pred = clf.predict(X_test) print "Accuracy:", accuracy_score(y_test, y_pred) pca = PCA() pca.plot_in_2d(X_test, y_pred)
def main(): data = load_iris_dataset(dir_path + r"/../data/iris.csv") X = data['X'] y = data['target'] X = normalize(X) X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.4) # MLP clf = MultilayerPerceptron(n_hidden=10) clf.fit(X_train, y_train, n_iterations=4000, learning_rate=0.01, plot_errors=True) y_pred = clf.predict(X_test) print "Accuracy:", accuracy_score(y_test, y_pred) # Reduce dimension to two using PCA and plot the results pca = PCA() pca.plot_in_2d(X_test, y_pred)
def main(): # Load the dataset data = load_iris_dataset(dir_path + r"/../data/iris.csv") X = data['X'] y = data['target'] # Three -> two classes X = X[y != 2] y = y[y != 2] X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33) # Fit and predict using LDA lda = LDA() lda.fit(X_train, y_train) y_pred = lda.predict(X_test) print "Accuracy:", accuracy_score(y_test, y_pred) pca = PCA() pca.plot_in_2d(X_test, y_pred)
def main(): # Load dataset data = load_iris_dataset(dir_path + r"/../data/iris.csv") X = data['X'] y = data['target'] X = normalize(X[y != 0]) y = y[y != 0] y[y == 1] = 0 y[y == 2] = 1 X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33) clf = LogisticRegression() clf.fit(X_train, y_train) y_pred = clf.predict(X_test) print "Accuracy:", accuracy_score(y_test, y_pred) # Reduce dimension to two using PCA and plot the results pca = PCA() pca.plot_in_2d(X_test, y_pred)