Ich habe erforscht und kämpfe um die beste Methode, um dieses Problem zu lösen, die ich habe. Ich habe einen Trainingsdatensatz und einen Testdatensatz. Dem Testdatensatz fehlen zwei Feature-Spalten, die das Trainingsdatenset enthält (Kanal und Sektor - beide bestehen aus 4 Klassen).Multioutput-multiclass Machine Learning in Python
Ich habe einen Entscheidungsbaum auf den Daten gebaut, aber ich kann nur auf Kanal oder Sektor damit trainieren, wenn ich in der Lage sein muss, auf beiden zu trainieren.
Kann mir jemand eine Empfehlung für die Implementierung von Multiclass Multioutput Machine Learning in Python geben?
import os
import subprocess
import pandas as pd
import numpy as np
from sklearn.tree import DecisionTreeClassifier, export_graphviz
def getPath(thisFile):
if os.path.exists(thisFile):
df = pd.read_csv(thisFile, header=0)
else:
return
return df
def visualize_tree(tree, feature_names):
with open("dt.dot", 'w') as f:
export_graphviz(tree, out_file=f,
feature_names=feature_names)
command = ["dot", "-Tpng", "dt.dot", "-o", "dt.png"]
try:
subprocess.check_call(command)
except:
exit("Could not run dot, ie graphviz, to "
"produce visualization")
data = np.loadtxt("newTrain2.csv", delimiter=',')
X = data[:, 1:4]
quantity = data[:, 2]
for i in range(len(quantity)):
if quantity[i] < 30:
quantity[i] = 1
if quantity[i] >= 25 and quantity[i] < 75:
quantity[i] = 2
if quantity[i] >= 75 and quantity[i] < 250:
quantity[i] = 3
if quantity[i] > 250:
quantity[i] = 4
revenue = data[:, 3]
for i in range(len(revenue)):
if revenue[i] < 1000:
revenue[i] = 1
if revenue[i] >= 1000 and revenue[i] < 4000:
revenue[i] = 2
if revenue[i] >= 4000 and revenue[i] < 10000:
revenue[i] = 3
if revenue[i] > 10000:
revenue[i] = 4
X[:, 1] = quantity
X[:, 2] = revenue
targets = data[:,4]
thisTree = DecisionTreeClassifier(min_samples_split=30, random_state=99)
thisTree.fit(X, targets)
visualize_tree(thisTree, ["product", "quantity", "revenue"])
Ich endete damit, aber ich bin sicher, es gibt bessere Methoden – wc01127