<jupyter_start><jupyter_text>Problem 1<jupyter_code>iris = load_iris()
X = iris.data
y = iris.target

X_train, X_test, y_train, y_test = model_selection.train_test_split(X,
                                                                    y,
                                                                    test_size=0.2, 
                                                                    random_state=10)

for i in range(5):
    clf = DecisionTreeClassifier(max_depth=i+1, min_samples_split=5, min_samples_leaf=2, 
                                 min_impurity_split=0.095, random_state=6)
    clf = clf.fit(X_train,
                  y_train)
    expected = y_test
    predicted = clf.predict(X_test)
    print('max_depth =', i+1, '\n', metrics.classification_report(expected,
                                        predicted))
    
    with open("iris.dot",
          'w') as f:
        f = export_graphviz(clf,
                            out_file=f)
    import os
    os.system("dot -Tpdf iris.dot -o iris"+str(i+1)+".pdf")
    os.unlink('iris.dot')
print(metrics.confusion_matrix(expected,
                               predicted))
with open("iris.dot",
          'w') as f:
    f = export_graphviz(clf,
                        out_file=f)
import os
os.system("dot -Tpdf iris.dot -o iris.pdf")
os.unlink('iris.dot')<jupyter_output><empty_output><jupyter_text>Problem 4<jupyter_code>N = 1000
u1 = 5
u2 = -5
s = 2

x1 = np.random.normal(u1,s,N)
x2 = np.random.normal(u2,s,N)
c1 = np.repeat('c1',N)
c2 = np.repeat('c2',N)

df1 = pd.DataFrame(dict(zip(['feature','class'],[x1,c1])))
df2 = pd.DataFrame(dict(zip(['feature','class'],[x2,c2])))
df = pd.concat([df1, df2])
dfclf = DecisionTreeClassifier(max_depth=2)
dfclf = dfclf.fit(df.iloc[:,1].values.reshape(-1, 1), df.iloc[:,0].values.reshape(-1, 1))
with open("p4.dot",
          'w') as f:
        f = export_graphviz(dfclf,
                            out_file=f)
import os
os.system("dot -Tpdf p4.dot -o p4.pdf")
os.unlink('p4.dot')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1429275505174963, 'fraction_numerical': 0.026121241991128634, 'mean_word_length': 1.9083094555873925, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '448394', 'license': 'MIT', 'n_tokens_mistral': 741, 'n_tokens_neox': 722, 'n_words': 117, 'path': 'Homework2/hw2.ipynb', 'repo_name': 'ZhihaoAi/CS-422-Assignments', 'size': '2029'}