Mining in Python (prediction using csv)

-1

I'm now starting to program in the Python language and I'm studying data mining with artificial neural network.

What should I do to make predictions from a .csv file? Then how do I save the results in another table?

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

Loading table

dataset = pd.read_csv('teste2.txt')
X = dataset.iloc[:, 1:20].values
y = dataset.iloc[:, 20].values

Separating training data

from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0)

Pre-processing

from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)

Creating RNA

import keras
from keras.models import Sequential
from keras.layers import Dense

classifier = Sequential()
classifier.add(Dense(units = 3, kernel_initializer = 'uniform', activation = 'relu', input_dim = 7))

classifier.add(Dense(units = 3, kernel_initializer = 'uniform', activation = 'relu'))

classifier.add(Dense(units = 1, kernel_initializer = 'uniform', activation = 'sigmoid'))

classifier.compile(optimizer = 'adam', loss = 'binary_crossentropy', metrics = ['accuracy'])

Training

classifier.fit(X_train, y_train, batch_size = 10, epochs = 100)

Predictions

Here I do not know what to do. I need to read another csv, make predictions and save to another file

    
asked by anonymous 11.11.2018 / 21:12

1 answer

0

I found out how to do it:

data_prediction = pd.read_csv('teste1.csv')
X_from_CSV = data_prediction.iloc[:, 1:20].values

X_test_new = sc.transform(X_from_CSV)
predictions = classifier.predict(X_test_new)
predictions = (predictions > 0.5)

df = pd.DataFrame({'Resultado':list(predictions)})
df.to_csv('res1.csv')
    
12.11.2018 / 05:25