0

I'm doing a sentiment analysis using python with machine learning, i am done from testing and training with my csv file, and i want to use the model i created for a new csv file i have. everything wok great but it require another step to set my model i trained for a new csv file.

#Importing necessary libraries

import nltk
import pandas as pd
from textblob import Word
from nltk.corpus import stopwords
from sklearn.preprocessing import LabelEncoder
from sklearn.metrics import classification_report,confusion_matrix,accuracy_score
from keras.models import Sequential
from keras.preprocessing.text import Tokenizer
from keras.preprocessing.sequence import pad_sequences
from keras.layers import Dense, Embedding, LSTM, SpatialDropout1D
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier

# split into train test sets

x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.33, random_state=1)

print(x_train.shape, x_test.shape, y_train.shape, y_test.shape)

# fit the model

model = RandomForestClassifier(random_state=1)

model.fit(x_train, y_train)

# make predictions

yhat = model.predict(x_test)

# evaluate predictions

acc = accuracy_score(y_test, yhat)

print('Accuracy: %.3f' % acc)

#The dataset is split into train and test sets and we can see that there are 67 rows for training and 33 rows for the test set.

from sklearn.datasets import load_iris

iris=load_iris()

x,y=iris.data,iris.target

x_train,x_test,y_train,y_test=train_test_split(x,y,

train_size=0.5,

test_size=0.5,

random_state=123)

y_test

this is my model with the testing and trainning

Yevhen Kuzmovych
  • 10,940
  • 7
  • 28
  • 48
shahad
  • 11
  • 2

0 Answers0