ऐसा करने का एक आसान तरीका एक Accord ID3 निर्णय पेड़ का उपयोग करना होगा।
यह चाल है कि कौन से इनपुट का उपयोग करना है - आप केवल एक्स पर ट्रेन नहीं कर सकते हैं - पेड़ उस से एक्स के भविष्य के मूल्यों के बारे में कुछ भी नहीं सीख पाएगा - हालांकि आप एक्स से व्युत्पन्न कुछ विशेषताएं बना सकते हैं (या वाई के पिछले मान) जो उपयोगी होंगे।
आम तौर पर इस तरह की समस्याओं के लिए - आप एक्स के बजाए वाई के पिछले मूल्यों (भविष्यवाणी की जा रही चीज़) से व्युत्पन्न सुविधाओं के आधार पर प्रत्येक भविष्यवाणी करेंगे। हालांकि, मान लीजिए कि आप प्रत्येक भविष्यवाणी के बीच अनुक्रमिक रूप से वाई देख सकते हैं (आप नहीं कर सकते फिर किसी भी arbitary एक्स के लिए भविष्यवाणी) तो मैं प्रस्तुत के रूप में सवाल के साथ रहना होगा।
मुझे नीचे इस समस्या को हल करने के लिए एक Accord ID3 निर्णय पेड़ बनाने में जाना पड़ा। मैंने सुविधाओं के रूप में x % n
के कुछ अलग-अलग मानों का उपयोग किया - उम्मीद है कि पेड़ इससे जवाब निकाल सकता है। असल में अगर मैं (x-1) % 4
को एक फीचर के रूप में जोड़ता हूं तो यह केवल एक ही स्तर पर ऐसा गुण कर सकता है - लेकिन मुझे लगता है कि पेड़ पैटर्न को ढूंढने के लिए और अधिक है।
x y
TrainingData 1 1
TrainingData 2 2
TrainingData 3 3
TrainingData 4 2
TrainingData 5 1
TrainingData 6 2
TrainingData 7 3
TrainingData 8 2
TrainingData 9 1
TrainingData 10 2
TrainingData 11 3
TrainingData 12 2
Prediction 13 1
Prediction 14 2
Prediction 15 3
Prediction 16 2
Prediction 17 1
Prediction 18 2
Prediction 19 3
Prediction 20 2
Prediction 21 1
Prediction 22 2
Prediction 23 3
Prediction 24 2
आशा है कि मदद करता है:
// this is the sequence y follows
int[] ysequence = new int[] { 1, 2, 3, 2 };
// this generates the correct Y for a given X
int CalcY(int x) => ysequence[(x - 1) % 4];
// this generates some inputs - just a few differnt mod of x
int[] CalcInputs(int x) => new int[] { x % 2, x % 3, x % 4, x % 5, x % 6 };
// for http://stackoverflow.com/questions/40573388/simple-accord-net-machine-learning-example
[TestMethod]
public void AccordID3TestStackOverFlowQuestion2()
{
// build the training data set
int numtrainingcases = 12;
int[][] inputs = new int[numtrainingcases][];
int[] outputs = new int[numtrainingcases];
Console.WriteLine("\t\t\t\t x \t y");
for (int x = 1; x <= numtrainingcases; x++)
{
int y = CalcY(x);
inputs[x-1] = CalcInputs(x);
outputs[x-1] = y;
Console.WriteLine("TrainingData \t " +x+"\t "+y);
}
// define how many values each input can have
DecisionVariable[] attributes =
{
new DecisionVariable("Mod2",2),
new DecisionVariable("Mod3",3),
new DecisionVariable("Mod4",4),
new DecisionVariable("Mod5",5),
new DecisionVariable("Mod6",6)
};
// define how many outputs (+1 only because y doesn't use zero)
int classCount = outputs.Max()+1;
// create the tree
DecisionTree tree = new DecisionTree(attributes, classCount);
// Create a new instance of the ID3 algorithm
ID3Learning id3learning = new ID3Learning(tree);
// Learn the training instances! Populates the tree
id3learning.Learn(inputs, outputs);
Console.WriteLine();
// now try to predict some cases that werent in the training data
for (int x = numtrainingcases+1; x <= 2* numtrainingcases; x++)
{
int[] query = CalcInputs(x);
int answer = tree.Decide(query); // makes the prediction
Assert.AreEqual(CalcY(x), answer); // check the answer is what we expected - ie the tree got it right
Console.WriteLine("Prediction \t\t " + x+"\t "+answer);
}
}
यह आउटपुट यह उत्पादन होता है:
और यहाँ उस के लिए कोड है।
संपादित करें: उदाहरण के नीचे, समय सूचकांक (एक्स) से प्राप्त सुविधाओं के बजाय लक्ष्य (वाई) के पिछले मूल्यों पर ट्रेन करने के लिए संशोधित किया गया है। इसका मतलब है कि आप अपनी श्रृंखला की शुरुआत में प्रशिक्षण शुरू नहीं कर सकते - क्योंकि आपको वाई के पिछले मूल्यों का पिछला इतिहास चाहिए। इस उदाहरण में मैंने x = 9 पर शुरुआत की क्योंकि यह वही अनुक्रम रखता है। जो बेहतर काम करेगा जहां वाई का निरपेक्ष मान सापेक्ष परिवर्तन के रूप में के रूप में महत्वपूर्ण नहीं है -
// this is the sequence y follows
int[] ysequence = new int[] { 1, 2, 3, 2 };
// this generates the correct Y for a given X
int CalcY(int x) => ysequence[(x - 1) % 4];
// this generates some inputs - just a few differnt mod of x
int[] CalcInputs(int x) => new int[] { CalcY(x-1), CalcY(x-2), CalcY(x-3), CalcY(x-4), CalcY(x - 5) };
//int[] CalcInputs(int x) => new int[] { x % 2, x % 3, x % 4, x % 5, x % 6 };
// for http://stackoverflow.com/questions/40573388/simple-accord-net-machine-learning-example
[TestMethod]
public void AccordID3TestTestStackOverFlowQuestion2()
{
// build the training data set
int numtrainingcases = 12;
int starttrainingat = 9;
int[][] inputs = new int[numtrainingcases][];
int[] outputs = new int[numtrainingcases];
Console.WriteLine("\t\t\t\t x \t y");
for (int x = starttrainingat; x < numtrainingcases + starttrainingat; x++)
{
int y = CalcY(x);
inputs[x- starttrainingat] = CalcInputs(x);
outputs[x- starttrainingat] = y;
Console.WriteLine("TrainingData \t " +x+"\t "+y);
}
// define how many values each input can have
DecisionVariable[] attributes =
{
new DecisionVariable("y-1",4),
new DecisionVariable("y-2",4),
new DecisionVariable("y-3",4),
new DecisionVariable("y-4",4),
new DecisionVariable("y-5",4)
};
// define how many outputs (+1 only because y doesn't use zero)
int classCount = outputs.Max()+1;
// create the tree
DecisionTree tree = new DecisionTree(attributes, classCount);
// Create a new instance of the ID3 algorithm
ID3Learning id3learning = new ID3Learning(tree);
// Learn the training instances! Populates the tree
id3learning.Learn(inputs, outputs);
Console.WriteLine();
// now try to predict some cases that werent in the training data
for (int x = starttrainingat+numtrainingcases; x <= starttrainingat + 2 * numtrainingcases; x++)
{
int[] query = CalcInputs(x);
int answer = tree.Decide(query); // makes the prediction
Assert.AreEqual(CalcY(x), answer); // check the answer is what we expected - ie the tree got it right
Console.WriteLine("Prediction \t\t " + x+"\t "+answer);
}
}
तुम भी वाई के पिछले मूल्यों के बीच मतभेदों पर प्रशिक्षण विचार कर सकते हैं।
यह शानदार है, मैंने इस उदाहरण से बहुत कुछ झुकाया (इनपुट और आउटपुट कैसे उत्पन्न करें) उदाहरण पूरी तरह से काम करता है। लेकिन 'असली मामले ", मैं, की गणना के लिए एक्स मान का उपयोग नहीं कर सकते हैं क्योंकि यह एक समय सेरी (जैसे x1 = 3:00 बजे, x2 = 4।: 00AM, x3 = 5: 00AM) है में है, इसलिए मैं केवल सभी वाई मूल्यों का एक समय सेरी है और अगले वाई मान क्या होगा .... भविष्यवाणी करने में सहायता के लिए यहां पैटन पर खोजना चाहते हैं .... अगर वह संवेदना करता है? – RHC
निश्चित - समय श्रृंखला के लिए लक्ष्य (वाई) के पिछले मानों का उपयोग करना अधिक स्वाभाविक है - कम से कम जब वास्तविक समय अप्रासंगिक है और मानों के बीच संबंध वह जगह है जहां पैटर्न झूठ बोलता है। – reddal
मैं जवाब जोड़ने के लिए उत्तर संपादित करूंगा कि उदाहरण को वाई – reddal