<jupyter_start><jupyter_text>Model Using DecisionTreeClassifier  Concatenated all the dataframes from 2011 to 2020 and selected the similar columns then used Decision TreeClassifier to predict the salaries (The salaries was binned into categories)<jupyter_code>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from IPython import display
import helper as h
import seaborn as sns
from sklearn.svm import SVC
from sklearn.tree import DecisionTreeClassifier
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
from sklearn.metrics import r2_score, mean_squared_error
from sklearn import preprocessing
%matplotlib inline
df = pd.read_csv('final_df.csv')
pd.set_option('display.max_columns', 500)
df.head()
df.shape
pd.options.display.max_colwidth = 200
pd.options.display.expand_frame_repr = 200

df['Age'][df['Age'].isin(['Under 18 years old'])] = '< 20'
df['Age'][df['Age'].isin(['18 - 24 years old'])] = '20-24'
df['Age'][df['Age'].isin(['35-39'])] = '34-39'
df['Age'][df['Age'].isin(['40-49'])] = '40-50'
df['Age'][df['Age'].isin(['50-59'])] = '51-60'
df['Age'][df['Age'].isin(['65 years or older', '>60'])] = '> 60'

df = df.dropna(subset=['Salary'], axis=0)
X = df.drop(['Salary', 'Occupation'], axis=1)
y = df['Salary']

cat_vars= X.select_dtypes(include=['object']).copy().columns
for var in cat_vars:
    # for each cat add dummy var, drop original column
    X = pd.concat([X.drop(var, axis=1), pd.get_dummies(X[var], prefix=var, prefix_sep='_', drop_first=True)], axis=1)

X.shape
#split the data into train and test
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state=5)

dtree_model = DecisionTreeClassifier(max_depth = 100).fit(X_train, y_train)
dtree_model.score(X_test, y_test)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15207877461706784, 'fraction_numerical': 0.038293216630196934, 'mean_word_length': 6.434959349593496, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 7, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '40290', 'license': 'CNRI-Python', 'n_tokens_mistral': 713, 'n_tokens_neox': 642, 'n_words': 167, 'path': 'Concatenated_df_from_2011_to_2020.ipynb', 'repo_name': 'EslamShash/StackOverFlow-Survey-Results', 'size': '1828'}