ml_decision_tree 1.0.0
ml_decision_tree: ^1.0.0 copied to clipboard
A native decision tree classifier (ID3) for Dart.
example/main.dart
import '../lib/ml_decision_tree.dart';
void main() {
final X = [
['Sunny', 'Hot', 'High'],
['Sunny', 'Hot', 'High'],
['Overcast', 'Hot', 'High'],
['Rain', 'Mild', 'High'],
['Rain', 'Cool', 'Normal'],
['Rain', 'Cool', 'Normal'],
['Overcast', 'Cool', 'Normal'],
['Sunny', 'Mild', 'High'],
['Sunny', 'Cool', 'Normal'],
['Rain', 'Mild', 'Normal'],
['Sunny', 'Mild', 'Normal'],
['Overcast', 'Mild', 'High'],
['Overcast', 'Hot', 'Normal'],
['Rain', 'Mild', 'High'],
];
final y = [
'No', 'No', 'Yes', 'Yes', 'Yes', 'No', 'Yes',
'No', 'Yes', 'Yes', 'Yes', 'Yes', 'Yes', 'No'
];
final model = DecisionTreeClassifier();
model.fit(X, y);
final testSamples = [
['Sunny', 'Cool', 'High'],
['Rain', 'Mild', 'Normal'],
['Overcast', 'Hot', 'High'],
];
final predictions = model.predict(testSamples);
for (int i = 0; i < testSamples.length; i++) {
print('Sample: ${testSamples[i]} => Prediction: ${predictions[i]}');
}
}