Data Science Asked by John Patrick Esperon Salvatin on April 11, 2021
I set my column 1 to 13 as X and column 14 as my Y.
My data set has 14 columns and 401 rows including the parameters
Bp,Sg,Al,Su,Rbc,Bu,Sc,Sod,Pot,Hemo,Wbcc,Rbcc,Htn,Class
80,1.02,1,0,1,36,1.2,137.53,4.63,15.4,7800,5.2,1,1
50,1.02,4,0,1,18,0.8,137.53,4.63,11.3,6000,4.71,0,1
80,1.01,2,3,1,53,1.8,137.53,4.63,9.6,7500,4.71,0,1
70,1.005,4,0,1,56,3.8,111,2.5,11.2,6700,3.9,1,1
80,1.01,2,0,1,26,1.4,137.53,4.63,11.6,7300,4.6,0,1
This is my code
import pandas as pd
from sklearn.metrics import accuracy_score
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
from PIL import Image
import streamlit as st
skipinitialspace = True
data = pd.read_csv("C:/Users/ADMIN/PycharmProjects/pythonProject/venv/KidneyPrediction/Kidney.csv")
st.subheader('Data Information: ')
st.dataframe(data)
st.write(data.describe())
chart = st.bar_chart(data)
X = data.iloc[:,0:13].values
X.reshape(-1, 13)
Y = data.loc[:,'Class'].values
Y.reshape(-1,1)
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.25, random_state=0)
The error is
ValueError: Expected 2D array, got scalar array instead: array=nan. Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.
Traceback:
File "C:UsersADMINPycharmProjectspythonProjectvenvKidneyPredictionKidney_Prediction.py", line 72, in <module>
prediction = RandomForestClassifier.predict(user_input)
Dont reshape X. It was fine in the first place. Try y = y.reshape(-1,1) You were missing the assignment back to y, since reshape returns a new object.
Answered by Jayaram Iyer on April 11, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP