<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mr X</title>
    <description>The latest articles on DEV Community by Mr X (@cbarecords).</description>
    <link>https://dev.to/cbarecords</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1468515%2F106ac9b5-600e-495a-88d6-7b425af6ef74.png</url>
      <title>DEV Community: Mr X</title>
      <link>https://dev.to/cbarecords</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/cbarecords"/>
    <language>en</language>
    <item>
      <title>KNN with PHP ML &amp; Rubix ML</title>
      <dc:creator>Mr X</dc:creator>
      <pubDate>Mon, 06 May 2024 15:45:42 +0000</pubDate>
      <link>https://dev.to/cbarecords/knn-with-php-ml-rubix-ml-3pph</link>
      <guid>https://dev.to/cbarecords/knn-with-php-ml-rubix-ml-3pph</guid>
      <description>&lt;p&gt;This post is for anybody who has tried to migrate to &lt;a href="https://rubixml.com"&gt;Rubix ML&lt;/a&gt; from &lt;a href="https://php-ml.readthedocs.io/en/latest/"&gt;PHP ML&lt;/a&gt; and more specifically anybody who is experimenting with K-Nearest Neighbors.  &lt;/p&gt;

&lt;p&gt;As probably anybody who gets familiar with the capabilities of regression does, I decided to use it to try to win the lottery. The basis of the argument is that on occasion regression gets surprisingly close to generating winning number combinations. &lt;/p&gt;

&lt;p&gt;You can check my blog and data tables here on my &lt;a href="https://lottery-predictions.online"&gt;lottery predictions&lt;/a&gt; website. I am currently mapping some data to graphs in some ongoing trend analysis. &lt;/p&gt;

&lt;p&gt;Anyway, I discovered when revisiting Rubix ML after starting with PHP ML that there were large differences in how the libraries handle data and its labels.  &lt;/p&gt;

&lt;p&gt;The process is simple I generate a simple multi-dimensional array, each item containing an integer for a month and a lottery number, and another array of labels simply 1 for a winning number or 0 for a losing number. After training with this data, I ask the program what numbers are likely to appear in a draw for every month of the year. &lt;/p&gt;

&lt;p&gt;Anyway, to cut a long story short to use PHP ML I coded the following&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public function knntest( $array, $distance ) {
$classifier = new KNearestNeighbors( $k = $distance, new Minkowski( 4 ) );
$classifier-&amp;gt;train( $this-&amp;gt;tensor[0], $this-&amp;gt;tensor[1] );
$predictions = array();
foreach ( $array as $key =&amp;gt; $check ) {
    foreach ( $check as $k =&amp;gt; $_check ) {
    $input  = array( $_check[0], $_check[1] );
    $nkpred = $classifier-&amp;gt;predict( $input );
    if ( $nkpred == '1' ) {
$month     = $key + 1;
$predictions[] = array(
'Month'   =&amp;gt; $month,
'Numbers' =&amp;gt; $_check[1],
);
}
}
}
return $predictions;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To process the same data with Rubix ML I had to write the following.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public function knntest( $array, $distance ) {
$classifier = new KNearestNeighbors( $distance, true, new Minkowski(4.0));
$dataset = new Labeled( $this-&amp;gt;tensor[0], $this-&amp;gt;tensor[1]);
$dataset-&amp;gt;apply(new OneHotEncoder());
$classifier-&amp;gt;train( $dataset );
$predictions = array();
foreach ( $array as $key =&amp;gt; $check ) {
$input  = new Unlabeled( $check );
$input-&amp;gt;apply(new OneHotEncoder());
$nkpred = $classifier-&amp;gt;predict( $input );
$i = 0;
$length = count($nkpred);
while($i &amp;lt; $length) {
if ( (string) $nkpred[$i] == '1' ) {
$month = $key + 1;
$predictions[] = array(
'Month'   =&amp;gt; $month,
'Numbers' =&amp;gt; $check[$i][1],
);
}
$i++;
}       
}
return $predictions;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see the contrast is huge. I found the way  I was working with Rubix was the only way I could get it to process the same data sets and labels.&lt;/p&gt;

&lt;p&gt;I figure this might help anybody who wants to start with KNN and Rubix after migrating from PHP ML.&lt;/p&gt;

&lt;p&gt;Personally speaking for the circumstance I am working with KNN in I am staying with PHP ML.&lt;/p&gt;

&lt;p&gt;Rubix seems to be group similar datasets together which is interesting itself. &lt;/p&gt;

</description>
      <category>machinelearning</category>
      <category>knn</category>
      <category>php</category>
    </item>
    <item>
      <title>Fetch Failed?</title>
      <dc:creator>Mr X</dc:creator>
      <pubDate>Sat, 04 May 2024 13:07:46 +0000</pubDate>
      <link>https://dev.to/cbarecords/fetch-failed-33la</link>
      <guid>https://dev.to/cbarecords/fetch-failed-33la</guid>
      <description>&lt;p&gt;This is more of a question than a thread.&lt;/p&gt;

&lt;p&gt;This is the scenario. I am working with nodes in node-RED. Basically I am requesting a list of files from One Drive and then sending this list (about 1000 files) through to a split node. A download of said files is then requested.&lt;/p&gt;

&lt;p&gt;This request is made with Fetch and via the M365 javascript SDK.&lt;/p&gt;

&lt;p&gt;The SDK has a get stream method that firstly gets the download URL and then requests the file as a binary stream.&lt;/p&gt;

&lt;p&gt;What happens ocassionally with this request is that I get a fetch failed error for multiple downloads. Sometimes fetch fails when a relatively small number of downloads are requested for example 500.&lt;/p&gt;

&lt;p&gt;I have monitored node-RED with Prometheus and have found that there is no noticable increase in event loop lag or excessive CPU usage.&lt;/p&gt;

&lt;p&gt;Part of my question is can a node in node-RED spawn a worker thread for the download operation, in theory reducing main thread work &lt;a href="https://nodejs.org/api/worker_threads.html"&gt;https://nodejs.org/api/worker_threads.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As far as I understand fetch failed means no response received. A failed request. So another question is, does the problem relate to the number of fetch requests being made.&lt;/p&gt;

&lt;p&gt;Is the node being swamped with that many requests that it is just getting some kind of throw back from Fetch. If this is the case what is the best diagnostic tool to get some qualitative data?&lt;/p&gt;

&lt;p&gt;Part of me thinks that this is a network error. However I am new to software such as shark wire so do not know how to identify possible issues.&lt;/p&gt;

</description>
      <category>node</category>
      <category>nodered</category>
      <category>fetch</category>
      <category>m365</category>
    </item>
  </channel>
</rss>
