"A friend to all is a friend to none. "

[1] AMPL-Intro

Preamble

supervised learning:

Learn to predict target values from labelled data

  • classification (target value are discrete classes)
  • regression(target values are continuous values)

unsupervised learning:

Find structure in unlabeled data

  • clustering(find similar instances in the data)
  • outlier detection(find unusual patterns)

 

Machine Learning Workflow

  • Representation
  • Evaluation
  • Optimization

 

An example of machine learning problem

The input data is a table

A KNN algorithm :

  1. A distance metric
    Euclidean(Minkowski with p = 2)
  2. Number of neighbors to look at
  3. Optional weighting function
  4. How to aggregate the classes of neighbor points
    Simple majority vote

KNN process:

  1. Import required modules and load data file
  2. Create train-test split
    x = fruits[{'mass','width','height'}]
    y = fruits['fruit_label']
    
    X_train, X_test, y_train, y_test = train_test_split(X,y,random_state=0)
    

     

  3. Create classifier object
    from sklearn.neighbors import KNeighborsClassifier
    knn = KNeighborsClassifier(n_neighbors = 5)
    

     

  4. Train the classifier(fit the estimator) using the training data
    knn.fit(X_train,y_train)
    

     

  5. Estimate the accuracy of the classifier
    knn.score(X_test,y_test)
    

     

  6. To predict
    fruit_prediction = knn.predict([{20,4.3,5.5}])
    lookup_fruit_name[fruit_prediction[0]]
    
  7. Plot decision boundary
    from adspy_shared_utilities import plot_fruit_knn
    plot_fruit_knn(X_train,y_train,5,;uniform)
    

 

Reference: https://www.coursera.org/learn/python-machine-learning/home/week/1

 

YOU MIGHT ALSO LIKE

0 0 vote
Article Rating
Subscribe
提醒
guest
0 评论
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x