I am building a regression platform as a cloud base service using the php-ai/php-ml library.
When I upload a Dataset with 2 features, the AI works fine. I get no errors and I get my expected output. However, when I upload a Dataset with only 1 feature, I get this error:
Phpml\Exception\LibsvmCommandException: vendor\php-ai\php-ml\bin\libsvm\svm-train.exe -s 3 -t 2 -c 10 -n 0.500000 -d 3 -r 0 -p 0.100000 -m 100.000000 -e 0.001000 -h 1 -b 0 with reason: Wrong input format at line 1
This error is being thrown when I attempt to train the AI using the classifier, which is done like so (note I store the classifier in the database to reuse its trained state):
$classifier->train($split->getTrainSamples(), $split->getTrainLabels());
Here is my full code snippet:
public function trainOrTest(Request $request) {
$csvFile = $request->file('dataframe');
if(isset($csvFile) && isset($request->features) && isset($request->ainame)) {
$regression = $this->getClassifierByName($request->ainame);
$dataset = new CsvDataset($csvFile, $request->features, true);
$classifier = !isset($regression) ? new SVR(Kernel::RBF, 3, 0.1, 10) : unserialize($regression->classifier);
$display = [];
$correct = 0;
$incorrect = 0;
if(!isset($request->predict)) {
$split = new StratifiedRandomSplit($dataset);
$classifier->train($split->getTrainSamples(), $split->getTrainLabels());
$predicted = $classifier->predict($split->getTestSamples());
foreach ($predicted as &$target) $target = round($target, 0);
$score = round((float)Accuracy::score($split->getTestLabels(), $predicted)) * 100;
foreach($split->getTestSamples() as $key => $sample)
$display[] = (object) ['output' => $predicted[$key], 'input' => $sample];
for($i = 0; $i <= count($predicted) -1; $i++) {
if($predicted[$i] == $split->getTestLabels()[$i]) {
$correct++;
}
else {
$incorrect++;
}
}
}
else {
$predicted = $classifier->predict($dataset->getSamples());
foreach ($predicted as &$target) $target = round($target, 0);
$score = round((float)Accuracy::score($dataset->getTargets(), $predicted)) * 100;
foreach($dataset->getSamples() as $key => $sample)
$display[] = (object) ['output' => $predicted[$key], 'input' => $sample];
for($i = 0; $i <= count($predicted) -1; $i++) {
if($predicted[$i] == $dataset->getTargets()[$i]) {
$correct++;
}
else {
$incorrect++;
}
}
}
# View Data
$stats = [['y' => $correct, 'label' => 'Correct'], ['y' => $incorrect, 'label' => 'Incorrect']];
$viewVar = (object) [
'results' => $display,
'score' => $score . '%',
'correct' => $correct,
'incorrect' => $incorrect
];
if(!isset($regression)) {
# Save the AI
$this->storeClassifier(serialize($classifier), $request->ainame);
}
else {
# Update the AI
$this->updateClassifier(serialize($classifier), $request->ainame);
}
# Store the compile statistics
$this->storeCompile($score, $correct, $incorrect, $this->getClassifierByName($request->ainame)->id);
# Return view
return view('home')->with('prediction', $viewVar)->with('statNew', $stats);
}
return back()->withInput();
}
Here is my CSV file which appears to work fine when I run this function:
"SibSp","Parch","Survived",
"1", "1", "1",
"3", "3", "1",
"4", "1", "0"
"4", "0", "1",
"5", "2", "0"
"3", "1", "0",
"2", "2", "1",
"0", "0", "1",
"1", "1", "1",
"3", "3", "1",
"4", "1", "0"
"4", "0", "1",
"5", "2", "0"
"3", "1", "0",
"2", "2", "1",
"0", "0", "1"
Here is the CSV file that causes the error in this function:
"sentence","language"
"Hello, do you know what time the movie is tonight?","english"
"I am calling to make reservations","english"
"I would like to know if it is at all possible to check in","english"
"What time does the swimming pool open?","english"
"Where is the games room?","english"
"We must call the police.","english"
"How many pupils are there in your school?","english"
"Twenty litres of unleaded, please.","english"
"Is it near here?","english"
"Do I have to change?","english"
"Which counter do I go to to change money?","english"
"I would like two postcards, please.","english"
"There was a big explosion.","english"
"Where is the television room?","english"
"Where's the nearest railway station?","english"
"The storms caused flooding.","english"
"Where is the duty free shop?","english"
"I witnessed it happening.","english"
"I would like two postcards, please.","english"
"How about going to the cinema?","english"
"Où est la boulangerie?","french"
"Je voudrais une boîte de chocolats.","french"
"Y a-t-il un autre hôtel près d'ici?","french"
"Vérifiez la batterie, s'il vous plaît.","french"
"La banque ouvre à quelle heure?","french"
"Est-ce que je peux l'écouter?","french"
"Vous devez faire une déclaration de perte.","french"
"Combien d'élèves y a-t-il dans votre collège?","french"
"Est-ce qu-il y a un car qui va à l'aéroport?","french"
"Nous voudrions rester jusqu'à dimanche prochain.","french"
"Je ne comprends pas.","french"
"Voici une ordonnance pour des comprimés.","french"
"Je n'ai qu'un billet de cinquante francs.","french"
"À quelle heure commence la dernière séance?","french"
"Faut-il changer?","french"
"Il n'avait pas la priorité.","french"
"Puis-je prendre les places à l'avance?","french"
"Elle a trente et un ans.","french"
"Pour aller à la pharmacie, s'il vous plaît?","french"
"Voulez-vous me peser ce colis, s'il vous plaît.","french"
"Ciao, ti va di andare al cinema?","italian"
"Mi sai dire quando aprono il negozio?","italian"
"Quando c'è l'ultimo autobus?","italian"
"Lo posso provare addosso?","italian"
"C'è una presa elettrica per il nostro caravan?","italian"
"Vorrei una scatola di cioccolatini.","italian"
"Non e' stata colpa mia.","italian"
"Sono molto scarso in fisica.","italian"
"Vorrei del vino bianco.","italian"
"Me lo puo' spiegare, per piacere.","italian"
"Vorrei chiamare a spese del ricevente.","italian"
"Ho perso il mio passaporto.","italian"
"Posso avere i biglietti del cinema per favore?","italian"
"Vorrei un pacchetto di biscotti.","italian"
"Quali materie studi (studia)?","italian"
"Quanto frequenti sono gli autobus?","italian"
"A che ora sara' la prossima raccolta?","italian"
"Vorrei prenotare un posto.","italian"
"Per favore, quanto costa spedire una lettera in Germania?","italian"
"Mio padre e' un programmatore.","italian"
Why is this causing the error? I have debugged my code to ensure that $request->features holds the value of 1 but I am getting no luck trying to figure out anything else.
from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2GSzK9s
via IFTTT
Aucun commentaire:
Enregistrer un commentaire