Machine Learning using python in 5 lines


when I asked my professor about machine learning he told the following:

Lets say you have a function f(a,b) = ax+by = z . Then there are sophisticated ways to learn a and b from a data set corresponding to [x,y,z]. This is (fitting in) machine learning.

So Here I am writing for someone who wants to use machine learning quickly in python:

First, let me write the general steps:

  1. Make the data in the right shape
  2. Create the learning object
  3. Fit the data using 1 & 2
  4. Predict on a new test data

Corresponding code

from sklearn.ensemble import RandomForestClassifier

[X,y] = extract_from_file('data_sheet.txt')#assuming you know #how to write this

function rf_classifier_object = RandomForestClassifier(max_depth=2, random_state=0),y) #The Learning step
rf_classifier_object.predict(X_test)#This will predict the new X_test data
Now you may replace 'RF' with any classifier or regressor as you like.  Let me know if you have any questions.



subscribe via RSS