Hallo liebes Forum,
Ich stehe ganz am Anfang mit meinen Versuchen in Python. Könnte jemand bei einer Aufgaben helfen bitte?
Ich komme leider nicht weiter Folgende Aufgabe ist zu lösen:
The task include predicting health risk of subjects from personal data and habits.
The patient info is represented as a tuple.
Implement the function decision that takes as input a tuple containing values for attributes (smoker,age,diet), and computes the output of the decision tree. Should return either 'less' or 'more'. No other outputs are valid:
def decision(x: Tuple[str, int, str]) -> str:
"""
This function implements the decision tree represented in the above image. As input the function
receives a tuple with three values that represent some information about a patient.
Args:
x (Tuple[str, int, str]): Input tuple containing exactly three values. The first element represents
a patient is a smoker this value will be 'yes'. All other values represent that
the patient is not a smoker. The second element represents the age of a patient
in years as an integer. The last element represents the diet of a patient.
If a patient has a good diet this string will be 'good'. All other
values represent that the patient has a poor diet.
Returns:
str: A string that has either the value 'more' or 'less'.
No other return value is valid
# Test expected 'more'
x = ("yes", 31, "good")
output = decision(x)
print(f"decision({x}) --> {output}")
t.assertIsInstance(output, str)
t.assertEqual(output, "more")
# Test expected 'less'
x = ("yes", 29, "poor")
output = decision(x)
print(f"decision({x}) --> {output}")
t.assertIsInstance(output, str)
t.assertEqual(output, "less")
Vielen Dank!!
Mit freundlichen Grüßen,
Berta
Classifying a single instance (function)
Also ich würde das hiermit lösen: https://scikit-learn.org/stable/modules/tree.html
Ich bin Pazifist und greife niemanden an, auch nicht mit Worten.
Für alle meine Code Beispiele gilt: "There is always a better way."
https://projecteuler.net/profile/Brotherluii.png
Für alle meine Code Beispiele gilt: "There is always a better way."
https://projecteuler.net/profile/Brotherluii.png
@ThomasL: sie muss keinen Baum lernen. Der Baum ist gegeben, und muss einfach in decision hart verdrahtet werden.
@Berta: du hast drei Eigenschaften, also maximal drei Entscheidungen. Was ist die erste Eigenschaft. Welchen Wertebereich hat die, und was passiert bei welchem Wert? Das steht doch in dem Baum den du hast. Wie sieht das aus? Ist dir klar, wie du wenn ich dir einen Vektor gebe, und den Baum, du den von Hand auswerten würdest?
@Berta: du hast drei Eigenschaften, also maximal drei Entscheidungen. Was ist die erste Eigenschaft. Welchen Wertebereich hat die, und was passiert bei welchem Wert? Das steht doch in dem Baum den du hast. Wie sieht das aus? Ist dir klar, wie du wenn ich dir einen Vektor gebe, und den Baum, du den von Hand auswerten würdest?
"This function implements the decision tree represented in the above image. "
Ooops, irgendwie habe ich das Ende des Satzes überlesen.
Ooops, irgendwie habe ich das Ende des Satzes überlesen.
Ich bin Pazifist und greife niemanden an, auch nicht mit Worten.
Für alle meine Code Beispiele gilt: "There is always a better way."
https://projecteuler.net/profile/Brotherluii.png
Für alle meine Code Beispiele gilt: "There is always a better way."
https://projecteuler.net/profile/Brotherluii.png