<jupyter_start><jupyter_text>Tirgul 7- Decision Tree and basic predictions<jupyter_code>import pandas as pd
import numpy as np
import sklearn as sk # SciKit learn package
from sklearn import tree
from sklearn.tree import DecisionTreeRegressor
# sklearn decision tree tutorials:
# https://www.youtube.com/watch?v=5il_Q4puBf4
# decision tree from scratch:
# https://heartbeat.fritz.ai/decision-tree-classification-in-python-with-scikit-learn-245502ada8aa
# let's read some data:
melbourne_file_path = 'melb_data.csv'
melbourne_data = pd.read_csv(melbourne_file_path) 
print(len(melbourne_data))
melbourne_data.head()
# drop na values
melbourne_data = melbourne_data.dropna(axis=0)
# Aquire data from multiple collumns
melbourne_features = ['Rooms', 'Bathroom', 'Landsize', 'Lattitude', 'Longtitude'] # these columns will be used to conclude about the label
X = melbourne_data[melbourne_features] # the features
y = melbourne_data['Price'] # the label
# Spliting the data to train and test set.  Specify a number for random_state to ensure same results each run
X_train, X_test, y_train, y_test = sk.model_selection.train_test_split(X, y, test_size=0.2, random_state=42) 
def mse(a,b): # remember functions in python
    return np.sqrt(np.square(a-b).mean())
# Define model.
melbourne_model = DecisionTreeRegressor(random_state=4)

# Fit model to data
melbourne_model.fit(X_train, y_train)
print("Making predictions for the following 5 houses:")
print(y_test.head())

print("The predictions are")
test_pred = melbourne_model.predict(X_test.head())
print(test_pred)
print("Making predictions all test houses:")
print(y_test)

print("The predictions are")
test_pred = melbourne_model.predict(X_test)
print(test_pred)

print("MSE: {:.3f}".format(mse(y_test.values,test_pred))) # MSE is the mean square error, a measure for data validation
# note the MSE is big, this is due to a high variance.
np.var(y_test)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10351966873706005, 'fraction_numerical': 0.009834368530020704, 'mean_word_length': 6.406130268199234, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 1, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '437703', 'license': 'MIT', 'n_tokens_mistral': 664, 'n_tokens_neox': 638, 'n_words': 180, 'path': 'tirgulim/tirgul7/tirgul_7.ipynb', 'repo_name': 'ShaiYona/Data-Science2021B', 'size': '1932'}