<jupyter_start><jupyter_text>Savinfg model in pickle file<jupyter_code>def saveModel(data):
  X= data.iloc[:,:-1].values
  y= data.iloc[:,-1].values
  le = LabelEncoder()
  print(y)
  y= le.fit_transform(y) 
  print(y)

  X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.30, random_state = 5)

  model = XGBClassifier(tree_method='gpu_hist',use_label_encoder=False)
  model.fit(X_train, y_train)
  pickle.dump(model, open('model.pkl','wb'))

  y_pred = model.predict(X_test)

  print('\nClassification report:\n', classification_report(y_test,y_pred))
  print('Confusion matrix: \n', confusion_matrix(y_test,y_pred))

  accuracy = accuracy_score(y_test,y_pred)
  accuracy_scores.append(accuracy)
  print("\n\nAccuracy:",accuracy_score(y_test, y_pred))

  print("\n\nPrecision:",precision_score(y_test, y_pred, average=None))
  print("\nRecall:",recall_score(y_test, y_pred, average=None))
  print("\nF1 score:",f1_score(y_test, y_pred, average=None))
df=pd.read_csv('combined_pssm2.csv')

X= df.iloc[:,:-1]
y= df.iloc[:,-1]
load_model=pickle.load(open("model.pkl","rb"))
print(load_model)
df.iloc[0,:-1].values
  X= df.iloc[:,:-1]
  y= df.iloc[:,-1]
  print(X)
  print(y)
le = LabelEncoder()
print(y)
y= le.fit_transform(y) 
print(y)

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.30, random_state = 5)

model = XGBClassifier(tree_method='gpu_hist',use_label_encoder=False)
X_train.shape
model.fit(X_train, y_train)
 y_pred = model.predict(X_test)

print('\nClassification report:\n', classification_report(y_test,y_pred))
print('Confusion matrix: \n', confusion_matrix(y_test,y_pred))

accuracy = accuracy_score(y_test,y_pred)
accuracy_scores.append(accuracy)
print("\n\nAccuracy:",accuracy_score(y_test, y_pred))

print("\n\nPrecision:",precision_score(y_test, y_pred, average=None))
print("\nRecall:",recall_score(y_test, y_pred, average=None))
print("\nF1 score:",f1_score(y_test, y_pred, average=None))
pickle.dump(model, open("model.dat", "wb"))
load_model = pickle.load(open("model.dat","rb"))
print(load_model)
type(df.iloc[0,:-1])
df.info()
type(X_test)
X_test.shape
tmp=df.iloc[0,:-1]
type(tmp)
result=pd.DataFrame([tmp])
print(result)
print(type(result))
result.head()
load_model.predict(result)

x.shape
X_test
print(type(X_test))
print(X_test.shape)
X_test[0]
y_pred=model.predict(X_test)
x=df.iloc[0,:-1].values
x.shape

cols_when_model_builds = load_model.get_booster().feature_names
print(cols_when_model_builds)
res=load_model.predict(X_test)
y=x.reshape(-1,1)
y
names=load_model.get_booster().feature_names
print(names)

def classModel3(data):
  X= data.iloc[:,:-1].values
  y= data.iloc[:,-1].values
  
  le = LabelEncoder()
  print(y)
  y= le.fit_transform(y) 
  print(y)

  X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.30, random_state = 5)

  model = XGBClassifier(tree_method='gpu_hist',use_label_encoder=False)
  model.fit(X_train, y_train)
  y_pred = model.predict(X_test)
  pickle.dump(model, open("model2.dat", "wb"))

  print('\nClassification report:\n', classification_report(y_test,y_pred))
  print('Confusion matrix: \n', confusion_matrix(y_test,y_pred))

  accuracy = accuracy_score(y_test,y_pred)
  #accuracy_scores.append(accuracy)
  print("\n\nAccuracy:",accuracy_score(y_test, y_pred))

  print("\n\nPrecision:",precision_score(y_test, y_pred, average=None))
  print("\nRecall:",recall_score(y_test, y_pred, average=None))
  print("\nF1 score:",f1_score(y_test, y_pred, average=None))
df=pd.read_csv("combined_pssm3.csv")
df.tail()
classModel3(df)


X= df.iloc[:,:-1]
y= df.iloc[:,-1]
print(X)
print(y)

le = LabelEncoder()
print(y)
y= le.fit_transform(y) 
print(y)

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.30, random_state = 5)

model = XGBClassifier(tree_method='gpu_hist',use_label_encoder=False)

model.fit(X_train, y_train)

y_pred = model.predict(X_test)

print('\nClassification report:\n', classification_report(y_test,y_pred))
print('Confusion matrix: \n', confusion_matrix(y_test,y_pred))

accuracy = accuracy_score(y_test,y_pred)
#accuracy_scores.append(accuracy)
print("\n\nAccuracy:",accuracy_score(y_test, y_pred))

print("\n\nPrecision:",precision_score(y_test, y_pred, average=None))
print("\nRecall:",recall_score(y_test, y_pred, average=None))
print("\nF1 score:",f1_score(y_test, y_pred, average=None))

pickle.dump(model, open("model2.dat", "wb"))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17019360648356596, 'fraction_numerical': 0.011481314723097704, 'mean_word_length': 7.320224719101123, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '302062', 'license': 'MIT', 'n_tokens_mistral': 1856, 'n_tokens_neox': 1820, 'n_words': 257, 'path': 'Final_model.ipynb', 'repo_name': 'PrincyGajera/SCOP', 'size': '4442'}