-
Notifications
You must be signed in to change notification settings - Fork 0
/
chatbot_model.py
43 lines (37 loc) · 1.31 KB
/
chatbot_model.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
# chatbot_model.py
import pandas as pd
from sklearn.naive_bayes import MultinomialNB
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.pipeline import Pipeline
class SymptomCheckerModel:
def __init__(self):
# Example dataset of symptoms and conditions
data = {
'symptoms': [
'cough, fever, fatigue',
'headache, dizziness',
'sore throat, cough, fever',
'chest pain, shortness of breath',
'fatigue, weight loss, nausea'
],
'condition': [
'Common Cold',
'Migraine',
'Flu',
'Heart Disease',
'Diabetes'
]
}
# Create a DataFrame
self.df = pd.DataFrame(data)
# Initialize a basic classifier with CountVectorizer and Naive Bayes
self.model = Pipeline([
('vectorizer', CountVectorizer()),
('classifier', MultinomialNB())
])
# Train the model
self.model.fit(self.df['symptoms'], self.df['condition'])
def predict_condition(self, symptoms: str):
return self.model.predict([symptoms])[0]
# Instantiate the model
symptom_checker = SymptomCheckerModel()