Creating a list for Azure Machine Learning

http://azure.microsoft.com/en-us/documentation/articles/machine-learning-consume-web-services/

I'm having the hardest time trying to figure out how to write this in PowerShell:

...

                                ColumnNames = new string[] {"cog_speed"},

                                Values = new string[,] {  { "0"},  { "1"}  }
...

My understanding is this is a list.  I've tried different things including the type accelerator [system.collections.arraylist].

Anyone have some ideas that I can try next?

If I could convert this Python code to PowerShell, that might help me also:

import json
data={"Inputs":{"input1":{"Col":["Surv","Pcl"],"Val":[["0","0"],["1","1"]]}},"GP":{}}
str.encode(json.dumps(data))

March 22nd, 2015 11:09am

#ColumnNames = new string[] {"cog_speed"},  Values = new string[,] {  { "0"},  { "1"}  }

$columnName=@{'cog_speed',@{'0','1'}}

I think you are really trying to create json objects.  Use ConvertTo-Json in PowerShell.

https://technet.microsoft.com/library/7375c4e6-b767-41cc-9c0d-37db1bbcf7bf%28v=wps.630%29.aspx?f=255&MSPPError=-2147217396


Free Windows Admin Tool Kit Click here and download it now
March 22nd, 2015 1:20pm

Here's the code that used to work:

https://github.com/marcoshaw/AzureML/blob/master/azureml_rest_api.ps1

Microsoft updated the API, and now I'm struggling to get my PowerShell working again.

I'll investigate...  I'm not sure your tip will work as things like "ColumnNames" must be in the JSON request.

Thanks for trying to help!

March 22nd, 2015 1:25pm

Here is your example in PowerShell:

convertFrom-json '{"Inputs":{"input1":{"Col":["Surv","Pcl"],"Val":[["0","0"],["1","1"]]}},"GP":{}}'

This creates a PowerShell object based on Json notation.

Here is your example going both ways:

PS C:\scripts> $x=convertFrom-json '{"Inputs":{"input1":{"Col":["Surv","Pcl"],"Val":[["0","0"],["1","1"]]}},"GP":{}}'
PS C:\scripts> $x |ConvertTo-Json
{
    "Inputs":  {
                   "input1":  {
                                  "Col":  "Surv Pcl",
                                  "Val":  "System.Object[] System.Object[]"
                              }
               },
    "GP":  {

           }
}

Also consider the following:

PS C:\scripts> $x.Inputs

input1
------
@{Col=System.Object[]; Val=System.Object[]}


PS C:\scripts> $x.Inputs.input1

Col                                                                                      Val
---                                                                                      ---
{Surv, Pcl}                                                                              {0 0, 1 1}


PS C:\scripts> $x.Inputs.input1.Col
Surv
Pcl
PS C:\scripts> $x.Inputs.input1['Surv']
PS C:\scripts> $x.Inputs.input1.col1
PS C:\scripts> $x.Inputs.input1.col
Surv
Pcl
PS C:\scripts> $x.Inputs.input1.col00.Surv

Free Windows Admin Tool Kit Click here and download it now
March 22nd, 2015 1:26pm

PS C:\scripts> $columnName=@{'cog_speed'=@{Surv='0';Pcl='1'}}
PS C:\scripts> $columnName|ConvertTo-Json
{
    "cog_speed":  {
                      "Surv":  "0",
                      "Pcl":  "1"
                  }
}

Your initial example would likely look something this.  Notice how the hashes are converted.  This is one way to get a list-like structure.

March 22nd, 2015 1:30pm

The Perl notation is not the same as PosH or Json so I am not sure how to get a pure PowerShell rendering.  We would have to know what the intended object looked like.

It looks like it wants to be parallel arrays but that I am not sure of.

Free Windows Admin Tool Kit Click here and download it now
March 22nd, 2015 1:38pm

Does this look close?

---Perl
data={
     "Inputs":{
         "input1":{
             "Col":["Surv","Pcl"],
             "Val":[
                  ["0","0"],
                  ["1","1"]
               ]
        }
        },
        "GP":{}

# PowerShell       }
$data=@{
          Inputs=@{
              input1=@{
                 Col=@("Surv","Pcl")
                 Val=@(
                  @("0","0"),
                  @("1","1")
                )
              }
           }
           GP=@{}
      }
March 22nd, 2015 1:43pm

The early example requires a "-depth" parameter.

PS C:\scripts>  $x=convertFrom-json '{"Inputs":{"input1":{"Col":["Surv","Pcl"],"Val":[["0","0"],["1","1"]]}},"GP":{}}'
PS C:\scripts> $x

Inputs                                                                                   GP
------                                                                                   --
@{input1=}


PS C:\scripts> $x|ConvertTo-Json -Depth 4
{
    "Inputs":  {
                   "input1":  {
                                  "Col":  [
                                              "Surv",
                                              "Pcl"
                                          ],
                                  "Val":  [
                                              [
                                                  "0",
                                                  "0"
                                              ],
                                              [
                                                  "1",
                                                  "1"
                                              ]
                                          ]
                              }
               },
    "GP":  {

           }
}
PS C:\scripts>
This generates and recovers the same Jsaon although the formatting is "prettier".  Note that we haveobjects and arrays to work with An object is identified by a hash and an array by an  array.
Free Windows Admin Tool Kit Click here and download it now
March 22nd, 2015 2:08pm

This will give you parallel arrays.

$z=@{
   ColumnNames=@("cog_speed")
   Values = 0,1
}
$z|ConvertTo-Json





March 22nd, 2015 2:17pm

A pure list:

PS C:\scripts> $h=[ordered]@{column1=3;column2=5;column3=99}
PS C:\scripts> $h|ConvertTo-Json
{
    "column1":  3,
    "column2":  5,
    "column3":  99
}
PS C:\scripts>

Free Windows Admin Tool Kit Click here and download it now
March 22nd, 2015 2:20pm

A pure array and an array of objects:

PS C:\scripts> $a=3,6,4,9,12,2
PS C:\scripts> $a|ConvertTo-Json
[
    3,
    6,
    4,
    9,
    12,
    2
]
PS C:\scripts> $f=dir *.txt |select name,fullname,length
PS C:\scripts> $f|COnvertTo-Json
[
    {
        "Name":  "test.txt",
        "FullName":  "C:\\scripts\\test.txt",
        "Length":  5865
    },
    {
        "Name":  "test2.txt",
        "FullName":  "C:\\scripts\\test2.txt",
        "Length":  5865
    }
]
PS C:\scripts>

March 22nd, 2015 2:23pm

Here is another example from the samples:

$json='{
  "Input": {
    "ConnectionString":     
    "DefaultEndpointsProtocol=https;AccountName=mystorageacct;AccountKey=mystorageacctKey",
    "RelativeLocation": "/mycontainer/mydatablob.csv",
    "BaseLocation": null,
    "SasBlobToken": null
  },
  "Output": null,
  "GlobalParameters": {}
}'

$request=@{
     Input=@{
         ConnectionString="DefaultEndpointsProtocol=https;AccountName=mystorageacct;AccountKey=mystorageacctKey"
         RelativeLocation="/mycontainer/mydatablob.csv"
         BaseLocation=$null
         SasBlobToken=$null
      }
      Output=$null
      GlobalParameters=@{}
}

         
Don't worry about the order of properties. It is an object and order does not matter.  Order only matters in arrays.

Free Windows Admin Tool Kit Click here and download it now
March 22nd, 2015 2:33pm

Thanks "jrv"!  I'd like to give you credit...  I'll post a link to this page/thread.  I marked what worked as the answer.
March 22nd, 2015 7:00pm

Good.  I am glad it helped.  I wasn't sure if I was being clear.

Thanks Marco.

Free Windows Admin Tool Kit Click here and download it now
March 22nd, 2015 7:02pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics