I am trying multiple disease prediction system and among them the error occur when trying malaria disease prediction system using svm algorithm. I have no idea how to fix the problem since other 4 disease predictions have no problem. I am new to ML field and this is the first project , so if the problem is too easy please understand me .
alueError: X has 16 features, but SVC is expecting 17 features as input.
Traceback:
File "C:\Users\HP\.conda\envs\DiseasePredictionSystem\Lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 584, in _run_script
exec(code, module.__dict__)
File "C:\Users\HP\Desktop\Multiple Disease Prediction System\multiple disease pred.py", line 404, in <module>
malaria_prediction = malaria_model.predict([user_input])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\HP\.conda\envs\DiseasePredictionSystem\Lib\site-packages\sklearn\svm\_base.py", line 820, in predict
y = super().predict(X)
^^^^^^^^^^^^^^^^^^
File "C:\Users\HP\.conda\envs\DiseasePredictionSystem\Lib\site-packages\sklearn\svm\_base.py", line 433, in predict
X = self._validate_for_predict(X)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\HP\.conda\envs\DiseasePredictionSystem\Lib\site-packages\sklearn\svm\_base.py", line 613, in _validate_for_predict
X = self._validate_data(
^^^^^^^^^^^^^^^^^^^^
File "C:\Users\HP\.conda\envs\DiseasePredictionSystem\Lib\site-packages\sklearn\base.py", line 588, in _validate_data
self._check_n_features(X, reset=reset)
File "C:\Users\HP\.conda\envs\DiseasePredictionSystem\Lib\site-packages\sklearn\base.py", line 389, in _check_n_features
raise ValueError(
UI in the streamlit :
#Malaria Prediction Page
if selected == 'Malaria Disease Prediction':
#page title
st.title('Malaria Prediction using ML')
col1, col2, col3, col4 = st.columns(4)
with col1:
age = st.text_input('Enter Your Age')
with col2:
sex = st.text_input('Male or Female [0/1] Male=0, Female=1')
with col3:
fever = st.text_input('Do you have fever? [0/1] Yes=1, No=0')
with col4:
cold = st.text_input('Are you feeling cold? [0/1] Yes=1, No=0')
with col1:
rigor = st.text_input('Do you feel rigor:high temperature and tremble with cold ?[0/1] Yes=1, No=0')
with col2:
fatigue = st.text_input('Do you feel fatigue?[0/1] Yes=1, No=0')
with col3:
headace = st.text_input('Do you feel headache?[0/1] Yes=1, No=0')
with col4:
bitter_tongue = st.text_input('Bitter tougue?[0/1] Yes=1, No=0')
with col1:
vomitting = st.text_input('Do you Vomit? [0/1] Yes=1, No=0')
with col2:
diarrhea = st.text_input('Diarrhea? [0/1] Yes=1, No=0')
with col3:
Convulsion = st.text_input('Have you ever muscular contract? [0/1] Yes=1, No=0')
with col4:
Anemia = st.text_input('Do you have anemia? [0/1] Yes=1, No=0')
with col1:
jundice = st.text_input('Do you have Jaundice? [0/1] Yes=1, No=0')
with col2:
cocacola_urine = st.text_input('Colour of urine is like cocacola? [0/1] Yes=1, No=0')
with col3:
hypoglycemia = st.text_input('Low in blood sugar level? [0/1] Yes=1, No=0')
with col4:
prostraction = st.text_input('Have you collapse? [0/1] Yes=1, No=0')
with col1:
hyperpyrexia = st.text_input('Body temperature up to 106.7°F or 41.5°C?[0/1] Yes=1, No=0')
#code for prediction
user_input = [age, sex, fever, cold, rigor, fatigue, headace, bitter_tongue, vomitting, diarrhea, Convulsion, Anemia, jundice, cocacola_urine, prostraction, hyperpyrexia]
user_input = [float(x) for x in user_input]
malaria_prediction = malaria_model.predict([user_input])
if malaria_prediction[0] == 1:
hypertension_diagnosis = 'The person has malaria disease'
else:
hypertension_diagnosis = 'The person does not have malaria disease'
st.success(malaria_diagnosis)
Your input was missing a feature hypoglycemia
, resulting in 16 inputs rather than 17. Should be:
...
#code for prediction
user_input = [age, sex, fever, cold, rigor, fatigue,
headace, bitter_tongue, vomitting, diarrhea,
Convulsion, Anemia, jundice, cocacola_urine,
hypoglycemia, #<---------- this was missing
prostraction, hyperpyrexia
]
...
You might also need to change the input to a numpy array: model.predict( np.array([user_input]) )
rather than just model.predict([user_input])
. But perhaps your UI handles that automatically.