ML_Ruby 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 34dae184f4e016ff1bb096a526d3d6c0b90c258611764d878937421dff40588d
4
- data.tar.gz: d04bc3f0684709b0facc19789493ab4fecad51c549fc0c059143c4e74f3ee029
3
+ metadata.gz: 64fda0d7d407a58ec1df7fa697db1e5a08d9fe8b4ca4b28e5533c50d985fa1c6
4
+ data.tar.gz: 26b26aac3b3260c77eda5aca6b4e04f3aa1320dd1c725a29d3d25b0e98a7c467
5
5
  SHA512:
6
- metadata.gz: 8d537746a497cd52caf070ee0c7ee429cbe910d6d870a7f8deb5608cb481131c14e95ae5b80fa7e1d0dbd3f81f0880ac132440f8351cbdd9d77e356f8d67067e
7
- data.tar.gz: 1c25a49ff36920de1a361bacf64dd3b27f18aaa1d0117dec0f103fbe7a4673372c3f49137c5633adf1961d7ed4fc817eed442c8245ec6b34563ba4d064b2a6de
6
+ metadata.gz: 55dc5ada8223599c639067eaf2cc301491b3c5fccf4d9a6d37ffeab286bec206cdd1154d9bd858f17a2002c9a31255e672660bf4e53f16b7214652796b8e2ca2
7
+ data.tar.gz: 1c9c36e421b9295ae086619c06fa333595d910128e0c0e4e4b4257360f2f9b84621742eb20bac257553fdbb31c1a273062e3a8ae955db92092778330b234160a
data/README.md CHANGED
@@ -20,6 +20,18 @@ Here are examples of how to install these python libraries via the command line
20
20
 
21
21
  $ gem install ML_Ruby
22
22
 
23
+ To include the "ML_Ruby" gem in your Ruby on Rails application, simply add the following line to your Gemfile:
24
+
25
+ ```
26
+ gem 'ML_Ruby'
27
+ ```
28
+
29
+ After adding the gem, run the bundle install command to install it:
30
+
31
+ ```
32
+ bundle install
33
+ ```
34
+
23
35
  # Usage
24
36
  - ### Linear Regression Algorithm - Sales Order Prediction Example
25
37
 
@@ -30,6 +42,28 @@ Here are examples of how to install these python libraries via the command line
30
42
  puts prediction
31
43
  ```
32
44
 
45
+ - ### Random Forest Regression Algorithm - Real Estate House Pricing Example
46
+
47
+ Consider yourself in the dynamic field of the Real Estate market, you have some apartments/houses data(number of bed rooms, price, approval_status) represented as input features and their corresponding prices.
48
+
49
+ ```
50
+ apartment_features = [
51
+ [3, 1500, 0],
52
+ [2, 1200, 1],
53
+ [4, 1800, 0],
54
+ [3, 1600, 1],
55
+ [5, 2200, 1]
56
+ ]
57
+ prices = [300000, 250000, 400000, 350000, 500000]
58
+ ```
59
+ Now if you would like to predict any new apartment's price, you can do so as below:
60
+ ```
61
+ ml = MLRuby::RandomForestRegression::Model.new(apartment_features,prices)
62
+ two_new_apartment_features = [[4, 5068, 0], [3, 1760, 1]]
63
+ prediction = ml.predict(two_new_apartment_features)
64
+ puts prediction
65
+ ```
66
+
33
67
  - ### Decision Tree Algorithm - User Approval Status Example
34
68
 
35
69
  Suppose you have a dataset that includes features such as social credit score, yearly income, and approval status (where 1 represents approval, and 0 represents non-approval). Now, you want to classify the approval status of a new person.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MLRuby
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
data/lib/ML_Ruby.rb CHANGED
@@ -19,6 +19,20 @@ module MLRuby
19
19
  end
20
20
  end
21
21
 
22
+ module RandomForestRegression
23
+ class Model
24
+ def initialize(x, y)
25
+ @x = x
26
+ @y = y
27
+ end
28
+ def predict(next_x)
29
+ script_path = "#{Gem.loaded_specs['ML_Ruby'].gem_dir}/lib/python/random_forest.py"
30
+ result = `#{MLRuby::PYTHON_PATH} #{script_path} "#{@x}, #{@y}, #{next_x}"`
31
+ result.gsub(/\[|\]/, '').split(' ').map(&:strip).map(&:to_f)
32
+ end
33
+ end
34
+ end
35
+
22
36
  module DecisionTreeClassifier
23
37
  class Model
24
38
  def initialize(data)
@@ -0,0 +1,60 @@
1
+ import requests
2
+
3
+ # Replace 'YOUR_API_KEY' with your actual Hugging Face API key
4
+ api_key = 'YOUR_API_KEY'
5
+
6
+ # Text to be summarized
7
+ text = """
8
+ Freedom of expression is a fundamental human right that holds immense importance in any democratic society. It serves as a platform for individuals to voice their opinions, share their thoughts and ideas, and engage in meaningful discussions and debates. However, the extent to which freedom of expression is upheld and practised varies from one country to another. In Bangladesh's case, although freedom of expression is enshrined in the constitution, its implementation faces significant challenges.
9
+
10
+ At first glance, it may appear that people in Bangladesh enjoy the freedom to express themselves without fear of persecution. The media also seems relatively free to report on matters of public interest. However, a closer examination reveals the existence of substantial limitations to this freedom.
11
+
12
+ One of the serious issues with freedom of expression in Bangladesh is its heavy bias towards certain individuals and groups. While some individuals, particularly those who are part of the ruling elite or possess political influence, can freely criticise the government and its policies, others do not have the same privilege. Those who lack political connections or are not part of the ruling elite face restrictions in expressing their opinions. They often become targets of persecution when they dare to speak out against the government or its policies.
13
+
14
+ Furthermore, freedom of expression is confined to specific topics in the country. People are allowed to discuss issues that do not directly affect the larger population, but they are prohibited from being critical of the government's failures or the shortcomings of its institutions. To achieve this, the government employs various tactics such as intimidation, harassment, imprisonment, and even violence. The media is not immune to such suppression, as journalists are frequently targeted and attacked for reporting on sensitive issues. Such restrictions do not align with the principles of democracy.
15
+
16
+ In Bangladesh, a unique style has emerged, favouring those who have political connections or are part of the ruling elite. This creates a significant power imbalance, silencing the voices of the majority while allowing the minority with access to power to dominate the conversation.
17
+
18
+ How did the country arrive at this point? Is it solely due to the efforts of successive governments to silence dissidents, or have the institutions tasked with protecting the rights of the people also succumbed to vested interests?
19
+
20
+ While it is valid to discuss the failure of institutions, a sizable portion of the blame falls on the media in Bangladesh as well. Impartial and unbiased journalism is increasingly limited in the country – not only due to informal embargoes and formal legal restrictions but also due to other factors. One crucial factor is the prevalence of media and journalists being aligned with partisan politics. While journalists having political alignments is not inherently wrong, it becomes problematic when they forget the fundamental principle of journalism: presenting the facts. Journalists with political biases or perceived biases often manipulate or distort information to support a specific political agenda or gain personal advantages. They tend to align themselves with the political party in power, compromising the freedom of expression that is crucial in a democratic society.
21
+
22
+ Another concerning trend in Bangladesh is the influence of businesses or business conglomerates that own media outlets. These entities often leverage their media ownership to protect their business interests by eliminating competitors or evading accountability for crimes and wrongdoing. In such cases, the media outlets tend to align closely with the power structure, serving the interests of those in power, rather than speaking up for the people.
23
+
24
+ Even in the presence of formal and informal restrictions imposed by the state, journalists should be able to report freely on matters of public interest. This freedom is essential for the press to remain relevant and create a platform for open dialogue among the people, their representatives, and public institutions. By doing so, the press can uphold the citizens' right to freedom of expression
25
+
26
+ Journalists and media organisations in Bangladesh must reaffirm their commitment to impartiality, independence, and the presentation of facts. By adhering to these principles, they can counteract the influence of partisan politics and business interests on journalism and contribute to the preservation of press freedom in the country. Additionally, efforts should be made to foster a media environment that encourages diverse perspectives and safeguards the integrity of journalism.
27
+
28
+ In a democracy, freedom of expression encompasses the right to criticise the government and its policies, and the press is expected to be free from bias. If Bangladesh aims to progress towards a more democratic society, it must ensure that freedom of expression is guaranteed to all its citizens, irrespective of their political affiliations or social status. But the question remains: how can the country do so?
29
+
30
+ """
31
+
32
+ # Define the endpoint URL
33
+ endpoint = 'https://api-inference.huggingface.co/models/facebook/bart-large-cnn'
34
+
35
+ # Define the headers with your API key
36
+ api_key = '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'
37
+ headers = {
38
+ 'Authorization': f'Bearer {api_key}',
39
+ }
40
+
41
+ # Define the payload with the text to be summarized
42
+ payload = {
43
+ 'inputs': text,
44
+ 'options': {
45
+ 'task': 'summarization',
46
+ },
47
+ }
48
+
49
+ # Make a POST request to the Hugging Face API
50
+ response = requests.post(endpoint, json=payload, headers=headers)
51
+
52
+ # Check if the request was successful
53
+ if response.status_code == 200:
54
+ result = response.json()
55
+ print(result)
56
+ #summary = result['summary']
57
+ #print("Summary:")
58
+ #print(summary)
59
+ else:
60
+ print("Error:", response.status_code, response.text)
@@ -0,0 +1,30 @@
1
+ import numpy as np
2
+ from sklearn.ensemble import RandomForestRegressor
3
+
4
+ import sys
5
+ import ast
6
+
7
+ class RandomForestModel:
8
+ def __init__(self, data):
9
+ self.data = data
10
+
11
+ def process_data(self):
12
+ self.X = self.data[0]
13
+ self.y = self.data[1]
14
+ self.new_prediction = self.data[2]
15
+
16
+ def train(self):
17
+ self.model = RandomForestRegressor(n_estimators=100, random_state=42)
18
+ self.model.fit(self.X, self.y)
19
+
20
+ def predict(self):
21
+ prediction = self.model.predict(self.new_prediction)
22
+ return prediction
23
+
24
+
25
+ data = ast.literal_eval(sys.argv[1])
26
+ random_forest_regression_model = RandomForestModel(data)
27
+ random_forest_regression_model.process_data()
28
+ random_forest_regression_model.train()
29
+ prediction = random_forest_regression_model.predict()
30
+ print(prediction)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ML_Ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abdul Barek
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-09-04 00:00:00.000000000 Z
11
+ date: 2023-09-18 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: This Ruby gem leverages Machine Learning(ML) techniques to make predictions(forecasts)
14
14
  and classifications in various applications. It provides capabilities such as predicting
@@ -33,6 +33,8 @@ files:
33
33
  - lib/python/k_nearest_neighbors.py
34
34
  - lib/python/linear_regression.py
35
35
  - lib/python/natural_language_processing/text_classifier.py
36
+ - lib/python/natural_language_processing/text_summary.py
37
+ - lib/python/random_forest.py
36
38
  - sig/ML_Ruby.rbs
37
39
  homepage: https://github.com/barek2k2/ML_Ruby
38
40
  licenses: []
@@ -41,7 +43,7 @@ metadata:
41
43
  homepage_uri: https://github.com/barek2k2/ML_Ruby
42
44
  source_code_uri: https://github.com/barek2k2/ML_Ruby
43
45
  changelog_uri: https://github.com/barek2k2/ML_Ruby
44
- post_install_message:
46
+ post_install_message:
45
47
  rdoc_options: []
46
48
  require_paths:
47
49
  - lib
@@ -56,8 +58,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
56
58
  - !ruby/object:Gem::Version
57
59
  version: '0'
58
60
  requirements: []
59
- rubygems_version: 3.0.3
60
- signing_key:
61
+ rubygems_version: 3.1.6
62
+ signing_key:
61
63
  specification_version: 4
62
64
  summary: Ruby gem uses Machine Learning(ML) techniques to make predictions and classifications,
63
65
  and it's powered by Python3 under the hood.