Skip to content

Simple example using House Pricing Scenario #53

Closed

Description

@TylerBrinkley

This is the first time I've looked into machine learning but I have a use case I'd like to test with it.

To get started I've created a simple example from the house pricing scenario which somewhat closely matches my use case but the results I'm getting are not at all close to what I expected. The data I'm providing is simply linear in terms of just the SqftLiving input parameter to the Price where Price = SqftLiving * 100. The SqftLot is held constant for training and prediction so it should be a non-factor.

I'm just trying to predict the Price when the SqftLiving is 1500 which with the linear model created by the provided data should make it about $150,000.

However, the results I get vary wildly from the negative to the postive 10's of millions every time I run the program which is unexpected. Could someone look into this simple example and let me know what if anything I'm doing is causing these poor results?

class Program
{
    static void Main(string[] args)
    {
        var filePath = "C://Temp/kc_house_data.csv";

        File.WriteAllText(filePath, @"100000,1000,8000
200000,2000,8000
400000,4000,8000");

        var pipeline = new LearningPipeline
        {
            new TextLoader<HousePriceData>(filePath, separator: ","),
            new ColumnConcatenator("Features", "SqftLiving", "SqftLot"),
            new StochasticDualCoordinateAscentRegressor()
        };

        var model = pipeline.Train<HousePriceData, HousePricePrediction>();

        var prediction = model.Predict(new HousePriceData { SqftLiving = 1500, SqftLot = 8000 });

        Console.WriteLine(prediction.Price);
        Console.ReadLine();
    }
}

public class HousePriceData
{
    [Column(ordinal: "0", name: "Label")]
    public float Price;

    [Column(ordinal: "1")]
    public float SqftLiving;

    [Column(ordinal: "2")]
    public float SqftLot;
}

public class HousePricePrediction
{
    [ColumnName("Score")]
    public float Price;
}

Activity

  1. Ivanidzo4ka commented on May 7, 2018

    @Ivanidzo4ka
    Contributor

    Hello Tyler.
    Let me point on the fact what you have only 3 data points, and our algorithms expected to be worked on millions of data points, with huge feature vector. For you as a person. it's obvious what formula states behind this 3 points, but from machine point of view, 3 points is not enough.

    I've made following change in your code:

            Random random = new Random();
            StringBuilder sb = new StringBuilder();
            for ( int i = 0; i < n; i++)
            {
                var sqft = random.NextDouble();
                sb.AppendLine(string.Format("{0},{1},8000", sqft*10, sqft ));
            }
            File.WriteAllText(filePath, sb.ToString());
    

    And I played with different values for n.
    n=100 gives me prediction for your example around 141 000 which is about 6% error.
    n=1000 gives me prediction 14910 which 0.6% error
    n=100000 gives me 14992 which is 0.06% error
    So the more data you give to algorithm, the better it performs.

    You can also play with different learning models. For example if I modify my generating code to make
    var sqft = random.NextDouble() *10_000;
    to reflect real values for square foots I can use FastTreeRegressor, and it will give me reasonable prediction (2% error) even with 100 examples.

  2. TylerBrinkley commented on May 7, 2018

    @TylerBrinkley
    Author

    @Ivanidzo4ka Thanks for the insight and the follow up with more data point results. I look forward to playing with this some more where I'll have a much larger data set.

  3. ghost locked as resolved and limited conversation to collaborators on Mar 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions