Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: X has 1 features, but KNeighborsClassifier is expecting 1441 features as input. #330

Closed
nehareddies opened this issue Mar 19, 2024 · 1 comment

Comments

@nehareddies
Copy link

Flask code

from flask import Flask, render_template, request
import pickle
from model import *
import pandas as pd
from sklearn.feature_extraction.text import TfidfVectorizer
from nltk.corpus import stopwords
from nltk.tokenize import word_tokenize
from nltk.stem import WordNetLemmatizer
from sklearn import *

app = Flask(__name__)
model = pickle.load(open('dengue.pkl', 'rb'))

@app.route('/')
def home():
    return render_template('index.html')

@app.route('/predict', methods=['POST', 'GET'])
def predict():
    symptoms = str(request.form['text'])
    stop_words = set(stopwords.words('english'))
    words = word_tokenize(symptoms.lower())
    words = [word for word in words if word.isalpha() and word not in stop_words]
    preprocessed_symptoms = ' '.join(words)
    tfidf_vectorizer = TfidfVectorizer(max_features=1500) 
    symptom_tfidf = tfidf_vectorizer.fit_transform([preprocessed_symptoms]).toarray
    X_train, X_test, y_train, y_test = train_test_split(tfidf_features, labels, test_size=0.2, random_state=42)
    knn_classifier = KNeighborsClassifier(n_neighbors=5)  
    knn_classifier.fit(X_train, y_train)
    predictions = knn_classifier.predict(X_test)
    symptom_tfidf = tfidf_vectorizer.fit_transform([preprocessed_symptoms])
    result = model.predict(symptom_tfidf)  

    if result[0] == "Dengue":
        result = "You are more likely to be suffering from dengue!"
    else :
        result = "You have less chances that you are suffering from dengue but there are chances that you are suffering from", result[0]


    return render_template('index.html', result=result)

if __name__ == '__main__':
    app.run(debug=True)
@SeppeDeWinter
Copy link
Collaborator

Hi @nehareddies

I think you placed this issue on the wrong repository?

All the best,

Seppe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants