main.py - from from from from matplotlib import colors...

This preview shows page 1 - 3 out of 5 pages.

from matplotlib import colorsfrom mlxtend.plotting import plot_decision_regionsfrom sklearn.datasets import load_digitsfrom turtle import colorimport pandas as pdimport matplotlib.pyplot as pltimport numpy as npimport pylab as plfrom sklearn import datasets, svmfrom sklearn.neighbors import KNeighborsClassifierfrom sklearn.preprocessing import StandardScalerfrom sklearn.linear_model import Perceptronfrom sklearn.model_selection import train_test_split, cross_val_scorefrom sklearn.metrics import accuracy_score, confusion_matrix, plot_confusion_matrixfrom sklearn.datasets import load_irisiris = load_iris()iris_data = iris.datairis_labels = iris.targetnp.random.seed(42)indices = np.random.permutation(len(iris_data))n_training_samples = 12learn_data = iris_data[indices[:-n_training_samples]]learn_labels = iris_labels[indices[:-n_training_samples]]test_data = iris_data[indices[-n_training_samples:]]test_labels = iris_labels[indices[-n_training_samples:]]# print(learn_data[:4], learn_labels[:4])# print(test_data[:4], test_labels[:4])neighbors = KNeighborsClassifier(n_neighbors=12)neighbors.fit(learn_data, learn_labels)KNeighborsClassifier(algorithm='auto', leaf_size=30, metric='euclidean',metric_params='None', n_jobs=None, n_neighbors=12, p=2, weights='uniform')predictedNeighbors = neighbors.predict(test_data)print("\nKNeighborsClassifier(algorithm='auto', leaf_size=30, metric='euclidean', metric_params='None', n_jobs=None, n_neighbors=12, p=2, weights='uniform')\n")print("\nK=12\nTest Sample: ")print(learn_labels)print("\nK=12 Sample Size = " + str(n_training_samples) + "\nTarget Values: ")print(predictedNeighbors)# print(iris_data)# print(iris_labels)class Perceptron:"""Perceptron neuron"""def __init__(self, learning_rate=0.1):
"""instantiate a new Perceptron:param learning_rate: coefficient used to tune the modelresponse to training data"""

Upload your study docs or become a

Course Hero member to access this document

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 5 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Summer
Professor
N/A

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture