forked from jwood803/MLNetExamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
20,828 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using Microsoft.ML.Data; | ||
|
||
namespace SelectAndShuffle | ||
{ | ||
public class HousingData | ||
{ | ||
[LoadColumn(0)] | ||
public float Longitude { get; set; } | ||
|
||
[LoadColumn(1)] | ||
public float Latitude { get; set; } | ||
|
||
[LoadColumn(2)] | ||
public float HousingMedianAge { get; set; } | ||
|
||
[LoadColumn(3)] | ||
public float TotalRooms { get; set; } | ||
|
||
[LoadColumn(4)] | ||
public float TotalBedrooms { get; set; } | ||
|
||
[LoadColumn(5)] | ||
public float Population { get; set; } | ||
|
||
[LoadColumn(6)] | ||
public float Households { get; set; } | ||
|
||
[LoadColumn(7)] | ||
public float MedianIncome { get; set; } | ||
|
||
[LoadColumn(8), ColumnName("Label")] | ||
public float MedianHouseValue { get; set; } | ||
|
||
[LoadColumn(9)] | ||
public string OceanProximity{ get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using Microsoft.ML.Data; | ||
|
||
namespace SelectAndShuffle | ||
{ | ||
public class HousingPrediction | ||
{ | ||
[ColumnName("Score")] | ||
public float PredictedPrice { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using Microsoft.ML; | ||
using System; | ||
|
||
namespace SelectAndShuffle | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
var context = new MLContext(); | ||
|
||
var data = context.Data.LoadFromTextFile<HousingData>("./housing.csv", hasHeader: true, separatorChar: ','); | ||
|
||
// Select columns | ||
var selectCols = context.Transforms.SelectColumns("HousingMedianAge", "TotalBedrooms"); | ||
var selectColsTransform = selectCols.Fit(data).Transform(data); | ||
|
||
//DisplayColumns(selectColsTransform); | ||
|
||
// Drop columns | ||
var dropCols = context.Transforms.DropColumns("Latitude", "Longitude"); | ||
var dropColsTransform = dropCols.Fit(data).Transform(data); | ||
|
||
//DisplayColumns(dropColsTransform); | ||
|
||
// Shuffle rows | ||
//DisplayColumns(data); | ||
|
||
var shuffleRows = context.Data.ShuffleRows(data, seed: 42); | ||
|
||
//DisplayColumns(shuffleRows); | ||
|
||
// Take rows | ||
var takeRows = context.Data.TakeRows(data, 2); | ||
|
||
//DisplayColumns(takeRows); | ||
|
||
// Filter rows | ||
var filterRows = context.Data.FilterRowsByColumn(data, "Population", lowerBound: 0, upperBound: 1000); | ||
|
||
DisplayColumns(filterRows); | ||
|
||
Console.ReadLine(); | ||
} | ||
|
||
private static void DisplayColumns(IDataView data) | ||
{ | ||
var preview = data.Preview(maxRows: 5); | ||
|
||
string previewData = ""; | ||
|
||
for (int i = 0; i < preview.RowView.Length; i++) | ||
{ | ||
foreach (var item in preview.RowView[i].Values) | ||
{ | ||
previewData += $"{item.Key}: {item.Value} "; | ||
} | ||
|
||
Console.WriteLine("----------------------------------"); | ||
Console.WriteLine(previewData); | ||
previewData = ""; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp2.2</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.ML" Version="1.3.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Update="housing.csv"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.