-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsoil_fertility.py
48 lines (30 loc) · 1.02 KB
/
soil_fertility.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# -*- coding: utf-8 -*-
"""Soil_Fertility.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1e0L-RbqU98Ibi-dZuUuYd7KsgNgqsdDa
"""
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import tensorflow as tf
from sklearn.ensemble import RandomForestClassifier
df = pd.read_csv('/content/data (1).csv')
df.head()
from sklearn.model_selection import train_test_split
X = df.drop('Output',axis=1)
y = df['Output']
sns.pairplot(data=df,hue="Output")
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
rfc = RandomForestClassifier()
rfc.fit(X_train,y_train)
pred = rfc.predict(X_test)
from sklearn.metrics import confusion_matrix, ConfusionMatrixDisplay
cm = confusion_matrix(y_test, pred, labels=rfc.classes_)
disp = ConfusionMatrixDisplay(confusion_matrix=cm,
display_labels=rfc.classes_)
disp.plot()
plt.show()
import pickle
pickle.dump(rfc,open('soil_fertility.pkl','wb'))