<jupyter_start><jupyter_text>Kullanıcıların verilerinden yani kullanıcıların yaşından, cinsiyetinden ve sevdikleri müziklerinden yola çıkarak onlara daha iyi müzik sunmaya çalışacağız. 1. adım data yı import et<jupyter_code>import pandas as pd
from sklearn.tree import DecisionTreeClassifier
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score

musicData = pd.read_csv('music.csv')
x = musicData.drop(columns=['genre'])
y = musicData['genre']
xTrain, xTest, yTrain, yTest = train_test_split(x, y, test_size=0.2)

model = DecisionTreeClassifier()
model.fit(xTrain, yTrain)
predictions = model.predict(xTest)

score = accuracy_score(yTest, predictions)
score<jupyter_output><empty_output><jupyter_text>2. adım veriyi temiz hale getir<jupyter_code>x = musicData.drop(columns=['genre'])
y = musicData['genre']
y<jupyter_output><empty_output><jupyter_text>3. adım verileri bölmek- % 70 veya % 80 nini model için % 20 sini test için bölünüz<jupyter_code>import pandas as pd
from sklearn.tree import DecisionTreeClassifier
from sklearn.externals import joblib

music_data = pd.read_csv('music.csv')
x = music_data.drop(columns=['genre'])
y = music_data['genre']

model = DecisionTreeClassifier()
model.fit(x, y)

joblib.dump(model, 'music-recommender.joblib')
#predictions = model.predict([[21,1]])<jupyter_output><empty_output><jupyter_text>music-recommender.joblib dosyasını oluşturalarak eğittiğimiz makineyi tekrar tekrar yazmamıza gerek kalmıyor.<jupyter_code>import pandas as pd
from sklearn.tree import DecisionTreeClassifier
from sklearn.externals import joblib

model = joblib.load('music-recommender.joblib')
predictions = model.predict([[21,1]])
predictions<jupyter_output><empty_output><jupyter_text>Görselleştirme<jupyter_code>import pandas as pd
from sklearn.tree import DecisionTreeClassifier
from sklearn import tree

music_data = pd.read_csv('music.csv')
x = music_data.drop(columns=['genre'])
y = music_data['genre']

model = DecisionTreeClassifier()
model.fit(x, y)

tree.export_graphviz(model, out_file='music-recommender.dot',
                     feature_names=['age','gender'],
                     class_names=sorted(y.unique()),
                     label='all',
                     rounded=True,
                     filled=True)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10589754627636677, 'fraction_numerical': 0.007318123116659492, 'mean_word_length': 5.775510204081633, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '363804', 'license': 'Apache-2.0', 'n_tokens_mistral': 886, 'n_tokens_neox': 829, 'n_words': 162, 'path': 'with mosh everybody python/machineLearningProje1.ipynb', 'repo_name': 'mrtyasar/PythonLearn', 'size': '2323'}