Changeset 16449


Ignore:
Timestamp:
12/23/18 09:16:37 (4 months ago)
Author:
gkronber
Message:

#2892: added a view for LR models with prediction intervals

Location:
trunk
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/HeuristicLab.Algorithms.DataAnalysis.Views/3.4/HeuristicLab.Algorithms.DataAnalysis.Views-3.4.csproj

    r15124 r16449  
    142142    <Compile Include="OneFactorClassificationModelView.Designer.cs">
    143143      <DependentUpon>OneFactorClassificationModelView.cs</DependentUpon>
     144    </Compile>
     145    <Compile Include="LinearRegressionModelView.cs">
     146      <SubType>UserControl</SubType>
     147    </Compile>
     148    <Compile Include="LinearRegressionModelView.Designer.cs">
     149      <DependentUpon>LinearRegressionModelView.cs</DependentUpon>
    144150    </Compile>
    145151    <Compile Include="RandomForestModelView.cs">
  • trunk/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/LinearRegressionModel.cs

    r16448 r16449  
    2222using System;
    2323using System.Collections.Generic;
     24using System.Drawing;
    2425using System.Linq;
    2526using HeuristicLab.Common;
     
    3536  [Item("Linear Regression Model", "Represents a linear regression model.")]
    3637  public sealed class LinearRegressionModel : RegressionModel, IConfidenceRegressionModel {
     38    public static new Image StaticItemImage {
     39      get { return HeuristicLab.Common.Resources.VSImageLibrary.Function; }
     40    }
    3741
    3842    [Storable]
     
    5155
    5256    public override IEnumerable<string> VariablesUsedForPrediction {
    53       get { return allowedInputVariables.Union(factorVariables.Select(f => f.Key)); }
     57      get { return doubleVariables.Union(factorVariables.Select(f => f.Key)); }
    5458    }
    5559
    5660    [Storable]
    57     private string[] allowedInputVariables;
     61    private string[] doubleVariables;
    5862    [Storable]
    5963    private List<KeyValuePair<string, IEnumerable<string>>> factorVariables;
     64
     65    /// <summary>
     66    /// Enumerable of variable names used by the model including one-hot-encoded of factor variables.
     67    /// </summary>
     68    public IEnumerable<string> ParameterNames {
     69      get {
     70        return factorVariables.SelectMany(kvp => kvp.Value.Select(factorVal => $"{kvp.Key}={factorVal}"))
     71          .Concat(doubleVariables)
     72          .Concat(new[] { "<const>" });
     73      }
     74    }
    6075
    6176    [StorableConstructor]
     
    6984      this.NoiseSigma = original.NoiseSigma;
    7085
    71       allowedInputVariables = (string[])original.allowedInputVariables.Clone();
     86      doubleVariables = (string[])original.doubleVariables.Clone();
    7287      this.factorVariables = original.factorVariables.Select(kvp => new KeyValuePair<string, IEnumerable<string>>(kvp.Key, new List<string>(kvp.Value))).ToList();
    7388    }
     
    8196      Array.Copy(covariance, C, covariance.Length);
    8297      this.NoiseSigma = noiseSigma;
    83       var stringInputVariables = factorVariables.Select(f => f.Key).Distinct();
    84       this.allowedInputVariables = doubleInputVariables.ToArray();
     98      this.doubleVariables = doubleInputVariables.ToArray();
     99      // clone
    85100      this.factorVariables = factorVariables.Select(kvp => new KeyValuePair<string, IEnumerable<string>>(kvp.Key, new List<string>(kvp.Value))).ToList();
    86101    }
     
    95110
    96111    public override IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
    97       double[,] inputData = dataset.ToArray(allowedInputVariables, rows);
     112      double[,] inputData = dataset.ToArray(doubleVariables, rows);
    98113      double[,] factorData = dataset.ToArray(factorVariables, rows);
    99114
     
    114129
    115130    public IEnumerable<double> GetEstimatedVariances(IDataset dataset, IEnumerable<int> rows) {
    116       double[,] inputData = dataset.ToArray(allowedInputVariables, rows);
     131      double[,] inputData = dataset.ToArray(doubleVariables, rows);
    117132      double[,] factorData = dataset.ToArray(factorVariables, rows);
    118133
Note: See TracChangeset for help on using the changeset viewer.