<jupyter_start><jupyter_text>Sk-Learn<jupyter_code>pip install -U scikit-multiflow
from skmultiflow.data import SEAGenerator
from skmultiflow.trees import HoeffdingTreeClassifier
from sklearn.model_selection import train_test_split, GridSearchCV
import numpy as np
import pandas as pd
from skmultiflow.data import DataStream
data1 = pd.read_csv ('/content/drive/MyDrive/Colab Notebooks/data_1.csv')
data2=pd.read_csv('/content/drive/MyDrive/Colab Notebooks/data_2.csv')
data1 = data1.drop_duplicates()
data2=data2.drop_duplicates()
x1=data1.drop(columns=['fetal_health']).astype(np.float32)
y1=data1['fetal_health']

x2=data2.drop(columns=['fetal_health']).astype(np.float32)
y2=data2['fetal_health']
for column in list(x1):
  x1[column] = (x1[column] - x1[column].min()) / (x1[column].max() - x1[column].min())


for column in list(x2):
  x2[column] = (x2[column] - x2[column].min()) / (x2[column].max() - x2[column].min())
x_train1,x_test1,y_train1,y_test1=train_test_split(x1,y1,test_size=0.2,random_state=20, stratify=y1)
x_train2,x_test2,y_train2,y_test2=train_test_split(x2,y2,test_size=0.2,random_state=20, stratify=y2)
stream = DataStream(x_train2.to_numpy(), y_train2.to_numpy())
vfdt = HoeffdingTreeClassifier()

x_train1=x_train1.to_numpy()
y_train1=y_train1.to_numpy()
vfdt.fit(x_train1,y_train1)

# Setup variables to control loop and track performance
correct_cnt = 0
n_samples = 0

stream.restart()
stream = DataStream(x_test1.to_numpy(), y_test1.to_numpy())
predict_list=[]

while stream.has_more_samples():
  X, y = stream.next_sample()
  y_pred = vfdt.predict(X)
  predict_list.append(y_pred)
  if y[0] == y_pred[0]:
        correct_cnt += 1
  n_samples+=1

stream.restart()
stream= DataStream(x_test2.to_numpy(), y_test2.to_numpy())

while stream.has_more_samples():
  X, y = stream.next_sample()
  y_pred = vfdt.predict(X)
  predict_list.append(y_pred)
  if y[0] == y_pred[0]:
        correct_cnt += 1
  n_samples+=1


print('Hoeffding Tree accuracy: {}'.format(correct_cnt / n_samples))

from sklearn.metrics import classification_report
test_data = pd.concat([y_test1, y_test2],axis=0)
print(classification_report(test_data,predict_list))<jupyter_output>precision    recall  f1-score   support

           1       0.92      0.91      0.91       329
           2       0.61      0.76      0.68        59
           3       0.65      0.43      0.52        35

    accuracy                           0.85       423
   macro avg       0.73      0.70      0.70       423
weighted avg       0.85      0.85      0.85       423<jupyter_text>Further Training<jupyter_code>while stream.has_more_samples():
  X, y = stream.next_sample()
  vfdt = vfdt.partial_fit(X, y)
correct_cnt = 0
n_samples = 0

stream.restart()
stream = DataStream(x_test1.to_numpy(), y_test1.to_numpy())
predict_list=[]

while stream.has_more_samples():
  X, y = stream.next_sample()
  y_pred = vfdt.predict(X)
  predict_list.append(y_pred)
  if y[0] == y_pred[0]:
        correct_cnt += 1
  n_samples+=1

stream.restart()
stream= DataStream(x_test2.to_numpy(), y_test2.to_numpy())

while stream.has_more_samples():
  X, y = stream.next_sample()
  y_pred = vfdt.predict(X)
  predict_list.append(y_pred)
  if y[0] == y_pred[0]:
        correct_cnt += 1
  n_samples+=1


print('Hoeffding Tree accuracy: {}'.format(correct_cnt / n_samples))
from sklearn.metrics import classification_report
test_data = pd.concat([y_test1, y_test2],axis=0)
print(classification_report(test_data,predict_list))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1310305452469312, 'fraction_numerical': 0.046817013988010275, 'mean_word_length': 4.27710843373494, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '459697', 'license': 'MIT', 'n_tokens_mistral': 1435, 'n_tokens_neox': 1369, 'n_words': 229, 'path': 'Assignment1/Model/C1_Model.ipynb', 'repo_name': 'Shanu85/DMG_Assignments', 'size': '3503'}