fork download
  1. import pandas as pd
  2. from sklearn.feature_extraction.text import CountVectorizer
  3. from sklearn.linear_model import LogisticRegression
  4. from sklearn.model_selection import train_test_split
  5. from sklearn.metrics import accuracy_score
  6.  
  7. Load the dataset
  8. data = pd.read_csv('fake_news.csv')
  9.  
  10. Extract the features and labels
  11. X = data['text']
  12. y = data['label']
  13.  
  14. Convert text to numerical features
  15. vectorizer = CountVectorizer()
  16. X_vectorized = vectorizer.fit_transform(X)
  17.  
  18. Split the data into training and testing sets
  19. X_train, X_test, y_train, y_test = train_test_split(X_vectorized, y, test_size=0.2, random_state=42)
  20.  
  21. Train the logistic regression model
  22. model = LogisticRegression()
  23. model.fit(X_train, y_train)
  24.  
  25. Evaluate the model
  26. y_pred = model.predict(X_test)
  27. accuracy = accuracy_score(y_test, y_pred)
  28. print(f'Accuracy: {accuracy:.2f}')
  29.  
Success #stdin #stdout #stderr 0.27s 40848KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Error: unexpected symbol in "import pandas"
Execution halted