<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Sentiments analysis challenge on movie review
Designed by 
Step1:  Trainning and testing the model with cross validation.
Step2:  The next cell may take some time.
Step3:  Trainning the model on the complete trainning dataset.
Step4:  Get the predictions.
Step5:  Save the results.
<ASSISTANT_TASK:>
Python Code:
from __future__ import division, print_function
import pandas as pd
import numpy as np
data_dir = 'data/'
# Load Original Data / contains data + labels 10 k 
train = pd.read_csv("../data/train.data")#.drop('id',axis =1 )
# Your validation data / we provide also a validation dataset, contains only data : 5k
valid = pd.read_csv("../data/valid.data")#.drop('id',axis =1 )
# final submission
test = pd.read_csv("../data/test.data")#.drop('id',axis =1 )
print("train size", len(train))
print("public test size", len(valid))
print("private test size",len(test))
# creating arrays from pandas dataframe
X_train = train['review'].values
y_train = train['label'].values
X_valid = valid['review'].values
X_test = test['review'].values
print("raw text : \n", X_train[0])
print("label :", y_train[0])
print(len(X_test))
Explanation: Sentiments analysis challenge on movie review
Designed by : Il faut sauver les datas, Ryan !
Boosz Paul 
Estrade Victor 
Gensollen Thibaut 
Rais Hadjer 
Sakly Sami
Introduction
The data set is composed of an equilibred number of positive /negative movie review. It will be on the form of 3 different CSV files. 
Train.csv contains 10k examples with 3 columns : id, label, review
Test_public.csv 5k examples with 3 columns : id, label, review
Test_private.csv contains 10k examples with only 2 columns : id, review
The goal is to predict the <code>predicted_label</code> column. The prediction quality is measured by the precision metrics. 
Results should be a txt file or csv file with 1 column : the predicted_class {0,1} as shown in this toolkit.
You have to keep the original order of the datasets.
Fetch the data and load it in pandas
The first things to do is to dawload all the data at the website : 
https://competitions.codalab.org/competitions/8131#learn_the_details-description
To rename them (remove the keys 'datasets_None_0b3a301a-be2e-4f21-8be9-dfa5c56439c4') to their original names:
train.data
valid.data
test.data
train_preprocessed.data
valid_preprocessed.data
test_preprocessed.data
and place them in a 'data/' folder.
End of explanation
from sklearn.ensemble import RandomForestClassifier
from sklearn.feature_extraction.text import TfidfVectorizer
# creating random forest classifier 
rfst = RandomForestClassifier(n_estimators = 100)
# TfIdf Vectorizer with default parameters 
myTfidfVect = TfidfVectorizer(stop_words='english', max_features=30000)
X_train_transformed = myTfidfVect.fit_transform(X_train)
Explanation: Trainning and testing the model with cross validation.
End of explanation
from sklearn.cross_validation import cross_val_score
scores = cross_val_score(rfst, X_train_transformed, y_train,
               scoring='accuracy', cv=5)
print('accuracy :', np.mean(scores), '% +/-', np.std(scores), '%')
Explanation: The next cell may take some time.
End of explanation
rfst.fit(X_train_transformed, y_train)
print('Model trainned.')
Explanation: Trainning the model on the complete trainning dataset.
End of explanation
X_valid_transformed = myTfidfVect.transform(X_valid)
X_test_transformed = myTfidfVect.transform(X_test)
prediction_valid = rfst.predict(X_valid_transformed)
prediction_test = rfst.predict(X_test_transformed)
pd.DataFrame(prediction_valid[:5], columns=['prediction'])
Explanation: Get the predictions.
End of explanation
import os
if not os.path.isdir(os.path.join(os.getcwd(),'results')):
    os.mkdir(os.path.join(os.getcwd(),'results'))
np.savetxt('results/valid.predict', prediction_valid, fmt='%d')
np.savetxt('results/test.predict', prediction_test, fmt='%d')
Explanation: Save the results.
End of explanation
<END_TASK>