How a Decision Tree Learns Patterns in Machine Learning › Forums › Python › CS50’s Introduction to Artificial Intelligence with Python › How a Decision Tree Learns Patterns in Machine Learning This topic is empty. Viewing 1 post (of 1 total) Author Posts May 14, 2026 at 1:49 am #6575 Rajeev BagraKeymaster When we train a machine learning model like a DecisionTreeRegressor, the model does not “understand” data like humans do. Instead, it learns by finding mathematical rules that reduce prediction errors. Step 1: Provide Training Data Suppose we have house data like this: Size (sq ft) Rooms Price 800 2 120000 1000 3 150000 2000 4 300000 2500 5 400000 In machine learning: Features (inputs) → X Target (answer/output) → y Example: X = home_data[features] y = home_data['SalePrice'] Step 2: Train the Model The model is trained using: iowa_model.fit(X, y) This means: Study the relationship between house features and actual prices. Step 3: The Model Starts Asking Questions A Decision Tree learns by creating rules. It searches for questions that best separate cheaper houses from expensive houses. For example: Is size < 1500? If YES: Likely cheaper houses If NO: Likely more expensive houses Then it keeps splitting again. Example: Is number_of_rooms < 4? </code Author Posts Viewing 1 post (of 1 total) You must be logged in to reply to this topic. Log In Username: Password: Keep me signed in Log In Log in / Register