Python mining (prediction using csv)

Asked

Viewed 401 times

0

I am now starting programming in Python language and I am studying data mining with artificial neural network.

What should I do to make predictions from a . csv file? Then how to 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 Data from Training

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 don’t know what to do. I need to read another csv, make predictions and save to another file

1 answer

0

figured out how to do:

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')

Browser other questions tagged

You are not signed in. Login or sign up in order to post.