Skip to content

Commit

Permalink
Merge pull request #6689 from jaymathe/dp2-jm
Browse files Browse the repository at this point in the history
2 additional ML articles with C# code edit
  • Loading branch information
cjgronlund committed Jan 15, 2015
2 parents 449ca74 + a799342 commit d299780
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 50 deletions.
49 changes: 24 additions & 25 deletions articles/machine-learning-r-csharp-cluster-model.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,37 +26,36 @@ There are multiple ways of consuming the service in an automated fashion (an exa

###Starting C# code for web service consumption:

public class Input{
public double Recency;
public double Frequency;
public double Monetary;
public double Time;
public double Class;
public class Input
{
public string value;
public string k;
}

public AuthenticationHeaderValue CreateBasicHeader(string username, string password)
{
byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(username + ":" + password);
return new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
}

public AuthenticationHeaderValue CreateBasicHeader(string username, string password)
{
byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(username + ":" + password);
System.Diagnostics.Debug.WriteLine("AuthenticationHeaderValue" + new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray)));
return new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
}

void Main()
{
var input = new Input(){Recency =1, Frequency=0,Monetary=0,Time=1, Class= 0};
var json = JsonConvert.SerializeObject(input);
var acitionUri = "PutAPIURLHere,e.g.https://api.datamarket.azure.com/..../v1/Score";

var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Authorization = CreateBasicHeader("PutEmailAddressHere","ChangeToAPIKey");
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var query = httpClient.PostAsync(acitionUri,new StringContent(json));
var result = query.Result.Content;
var scoreResult = result.ReadAsStringAsync().Result;
scoreResult.Dump();
var input = new Input() { value = TextBox1.Text, k = TextBox2.Text };
var json = JsonConvert.SerializeObject(input);
var acitionUri = "PutAPIURLHere,e.g.https://api.datamarket.azure.com/..../v1/Score";
var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Authorization = CreateBasicHeader("PutEmailAddressHere", "ChangeToAPIKey");
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var response = httpClient.PostAsync(acitionUri, new StringContent(json));
var result = response.Result.Content;
var scoreResult = result.ReadAsStringAsync().Result;
}




#Creation of the web-service
>This web service was created using Azure ML. For a free trial, as well as introductory videos on creating experiments and [publishing web services](http://azure.microsoft.com/en-us/documentation/articles/machine-learning-publish-web-service-to-azure-marketplace/), please see [azure.com/ml](http://azure.com/ml). Below is a screenshot of the experiment that created the web service and example code for each of the modules within the experiment.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,37 +27,35 @@ There are multiple ways of consuming the service in an automated fashion (an exa

###Starting C# code for web service consumption:

public class Input{
public double Recency;
public double Frequency;
public double Monetary;
public double Time;
public double Class;
public class Input
{
public string value;
}

public AuthenticationHeaderValue CreateBasicHeader(string username, string password)
{
byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(username + ":" + password);
System.Diagnostics.Debug.WriteLine("AuthenticationHeaderValue" + new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray)));
return new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
}

public AuthenticationHeaderValue CreateBasicHeader(string username, string password)
{
byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(username + ":" + password);
return new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
}

void Main()
{
var input = new Input(){Recency =1, Frequency=0,Monetary=0,Time=1, Class= 0};
var json = JsonConvert.SerializeObject(input);
var acitionUri = "PutAPIURLHere,e.g.https://api.datamarket.azure.com/..../v1/Score";

var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Authorization = CreateBasicHeader("PutEmailAddressHere","ChangeToAPIKey");
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var query = httpClient.PostAsync(acitionUri,new StringContent(json));
var result = query.Result.Content;
var scoreResult = result.ReadAsStringAsync().Result;
scoreResult.Dump();
var input = new Input() { value = TextBox1.Text };
var json = JsonConvert.SerializeObject(input);
var acitionUri = "PutAPIURLHere,e.g.https://api.datamarket.azure.com/..../v1/Score";
var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Authorization = CreateBasicHeader("PutEmailAddressHere", "ChangeToAPIKey");
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var response = httpClient.PostAsync(acitionUri, new StringContent(json));
var result = response.Result.Content;
var scoreResult = result.ReadAsStringAsync().Result;
}




#Creation of the web-service
>This web service was created using Azure ML. For a free trial, as well as introductory videos on creating experiments and [publishing web services](http://azure.microsoft.com/en-us/documentation/articles/machine-learning-publish-web-service-to-azure-marketplace/), please see [azure.com/ml](http://azure.com/ml). Below is a screenshot of the experiment that created the web service and example code for each of the modules within the experiment.
Expand Down

0 comments on commit d299780

Please sign in to comment.