Machine Learning Tutorials
Install anaconda https://www.anaconda.com/
Open the terminal:
Hoomans-Mac-mini:~ hoomansalamat$ mkdir ML
Hoomans-Mac-mini:~ hoomansalamat$ cd ML
Hoomans-Mac-mini:ML hoomansalamat$ jupyter notebook
Download Video Game Sales from https://www.kaggle.com/gregorut/videogamesales and unzip to ML directory
###############Import CSV file#################
import pandas as pd
df = pd.read_csv('vgsales.csv')
df.shape
df.describe()
df.values
###############Predict#################
Create a music.csv file:
age gender genre
20 1 HipHop
23 1 HipHop
25 1 HipHop
26 1 Jazz
29 1 Jazz
30 1 Jazz
31 1 Classical
33 1 Classical
37 1 Classical
20 0 Dance
21 0 Dance
25 0 Dance
26 0 Acoustic
27 0 Acoustic
30 0 Acoustic
31 0 Classical
34 0 Classical
35 0 Classical
Let's create a model that predicts a music genre based on age and gender of people.
import pandas as pd
from sklearn.tree import DecisionTreeClassifier
music_data = pd.read_csv('music.csv')
#music_data
X=music_data.drop(columns=['genre'])
#X
y = music_data['genre']
#y
model = DecisionTreeClassifier()
model.fit(X,y)
predictions = model.predict([[21,1], [22,0]])
predictions
Comments
Post a Comment